this.BX=this.BX||{};(function(e,t,i,s,n){"use strict";(function(){BX.namespace("BX.Main.ui.block");BX.Main.ui.block["date-group"]=function(e){var t,i,s,n,a;t={block:"main-ui-control-field-group",name:e.name+"_datesel",mix:"mix"in e?e.mix:null,attrs:{"data-type":"type"in e?e.type:"","data-name":"name"in e?e.name:"","data-time":e.enableTime},content:[]};if("label"in e&&BX.type.isNotEmptyString(e.label)){var r=e.label;if("icon"in e&&BX.Type.isPlainObject(e.icon)){r=[{block:"main-ui-control-field-label-icon",tag:"img",attrs:{title:e.icon.title?e.icon.title:"",src:e.icon.url}},{block:"main-ui-control-field-label-text",tag:"span",content:r}]}n={block:"main-ui-control-field-label",tag:"span",attrs:{title:e.label},content:r};t.content.push(n)}i={block:"main-ui-control-field",dragButton:false,content:{block:"main-ui-select",tabindex:"tabindex"in e?e.tabindex:"",value:"value"in e?e.value:"",items:"items"in e?e.items:"",name:"name"in e?e.name+"_datesel":"",params:"params"in e?e.params:"",valueDelete:false}};t.content.push(i);if("content"in e&&BX.type.isArray(e.content)){e.content.forEach((function(e){t.content.push(e)}))}if("content"in e&&(BX.type.isPlainObject(e.content)||BX.type.isNotEmptyString(e.content))){t.content.push(e.content)}s={block:"main-ui-item-icon-container",content:{block:"main-ui-item-icon",mix:["main-ui-delete","main-ui-filter-field-delete"],tag:"span",attrs:{title:"deleteTitle"in e&&e.deleteTitle?e.deleteTitle:""}}};t.content.push(s);if(!("dragButton"in e)||e.dragButton!==false){a={block:"main-ui-filter-icon-grab",mix:["main-ui-item-icon"],tag:"span",attrs:{title:"dragTitle"in e&&e.dragTitle?e.dragTitle:""}};t.content.push(a)}return t}})();(function(){BX.namespace("BX.Main.ui.block");BX.Main.ui.block["main-ui-control-field"]=function(e){var t,i,s,n,a;t={block:"main-ui-control-field",mix:"mix"in e?e.mix:null,attrs:{"data-type":"type"in e?e.type:"","data-name":"name"in e?e.name:""},content:[]};if("label"in e&&BX.type.isNotEmptyString(e.label)){var r=e.label;if("icon"in e&&BX.Type.isPlainObject(e.icon)){r=[{block:"main-ui-control-field-label-icon",tag:"img",attrs:{title:e.icon.title?e.icon.title:"",src:e.icon.url}},{block:"main-ui-control-field-label-text",tag:"span",content:r}]}n={block:"main-ui-control-field-label",tag:"span",attrs:{title:e.label},content:r};t.content.push(n)}if(BX.type.isArray(e.content)){e.content.forEach((function(e){t.content.push(e)}))}else if(BX.type.isPlainObject(e.content)||BX.type.isNotEmptyString(e.content)){t.content.push(e.content)}if("valueDelete"in e&&e.valueDelete===true){s={block:"main-ui-control-value-delete",content:{block:"main-ui-control-value-delete-item",tag:"span"}};t.content.push(s)}if("deleteButton"in e&&e.deleteButton===true){i={block:"main-ui-item-icon-container",content:{block:"main-ui-item-icon",mix:["main-ui-delete","main-ui-filter-field-delete"],tag:"span",attrs:{title:"deleteTitle"in e&&e.deleteTitle?e.deleteTitle:""}}};t.content.push(i)}if(!("dragButton"in e)||e.dragButton!==false){a={block:"main-ui-filter-icon-grab",mix:["main-ui-item-icon"],tag:"span",attrs:{title:"dragTitle"in e&&e.dragTitle?e.dragTitle:""}};t.content.push(a)}return t}})();(function(){BX.namespace("BX.Main.ui.block");BX.Main.ui.block["main-ui-control-field-group"]=function(e){var t,i,s,n;t={block:"main-ui-control-field-group",mix:"mix"in e?e.mix:null,attrs:{"data-type":"type"in e?e.type:"","data-name":"name"in e?e.name:""},content:[]};if("label"in e&&BX.type.isNotEmptyString(e.label)){var a=e.label;if("icon"in e&&BX.Type.isPlainObject(e.icon)){a=[{block:"main-ui-control-field-label-icon",tag:"img",attrs:{title:e.icon.title?e.icon.title:"",src:e.icon.url}},{block:"main-ui-control-field-label-text",tag:"span",content:a}]}s={block:"main-ui-control-field-label",tag:"span",attrs:{title:e.label},content:a};t.content.push(s)}if(BX.type.isArray(e.content)){e.content.forEach((function(e){t.content.push(e)}))}else if(BX.type.isPlainObject(e.content)||BX.type.isNotEmptyString(e.content)){t.content.push(e.content)}if("deleteButton"in e&&e.deleteButton===true){i={block:"main-ui-item-icon-container",content:{block:"main-ui-item-icon",mix:["main-ui-delete","main-ui-filter-field-delete"],tag:"span",attrs:{title:"deleteTitle"in e&&e.deleteTitle?e.deleteTitle:""}}};t.content.push(i)}if(!("dragButton"in e)||e.dragButton!==false){n={block:"main-ui-filter-icon-grab",mix:["main-ui-item-icon"],tag:"span",attrs:{title:"dragTitle"in e&&e.dragTitle?e.dragTitle:""}};t.content.push(n)}return t}})();(function(){BX.namespace("BX.Main.ui.block");BX.Main.ui.block["main-ui-control-string"]=function(e){return{block:"main-ui-control-string",mix:["main-ui-control"],tag:"input",attrs:{type:"type"in e?e.type:"text",name:"name"in e?e.name:"",placeholder:"placeholder"in e?e.placeholder:"",tabindex:"tabindex"in e?e.tabindex:"",value:"value"in e?e.value:""}}}})();(function(){BX.namespace("BX.Main.ui.block");BX.Main.ui.block["main-ui-control-textarea"]=function(e){return{block:"main-ui-control-string",mix:["main-ui-control main-ui-control-textarea"],tag:"textarea",attrs:{name:"name"in e?e.name:"",placeholder:"placeholder"in e?e.placeholder:"",tabindex:"tabindex"in e?e.tabindex:""},content:"value"in e?e.value:""}}})();(function(){BX.namespace("BX.Main.ui.block");BX.Main.ui.block["main-ui-filter-field-list-item"]=function(e){var t={block:"main-ui-select-inner-label",content:"label"in e?e.label:""};var i={block:"main-ui-filter-field-list-item",mix:"main-ui-select-inner-item",attrs:{"data-id":e.id,"data-name":e.name,"data-item":"item"in e?JSON.stringify(e.item):{}},events:{click:"onClick"in e?e.onClick:""},content:t};return i}})();(function(){BX.namespace("BX.Main.ui.block");BX.Main.ui.block["main-ui-filter-info"]=function(e){return{block:"main-ui-filter-info",tag:"span",content:e.content,attrs:{title:e.title}}}})();(function(){BX.namespace("BX.Main.ui.block");BX.Main.ui.block["main-ui-number"]=function(e){var t,i,s;t={block:"main-ui-number",mix:["main-ui-control"],content:[]};if("mix"in e&&BX.type.isArray(e.mix)){e.mix.forEach((function(e){t.mix.push(e)}))}i={block:"main-ui-number-input",mix:["main-ui-control-input"],tag:"input",attrs:{type:"number",name:"name"in e?e.name:"",tabindex:"tabindex"in e?e.tabindex:"",value:"value"in e?e.value:"",placeholder:"placeholder"in e?e.placeholder:"",autocomplete:"off"}};t.content.push(i);if("valueDelete"in e&&e.valueDelete===true){s={block:"main-ui-control-value-delete",content:{block:"main-ui-control-value-delete-item",tag:"span"}};t.content.push(s)}return t}})();(function(){BX.namespace("BX.Main.ui.block");BX.Main.ui.block["main-ui-search-square"]=function(e){var t=["main-ui-filter-search-square"];if("isPreset"in e&&e.isPreset){t.push("main-ui-filter-search-square-preset")}var i="title"in e?e.title:"";var s="name"in e?BX.util.htmlspecialcharsback(e.name):"";if("icon"in e&&BX.Type.isPlainObject(e.icon)){var n=e.icon.title;i=i.length?n+": "+i:"";s=s.length?n+": "+s:""}return{block:"main-ui-square",mix:t,attrs:{"data-item":"item"in e?JSON.stringify(e.item):"",title:i},content:[{block:"main-ui-square-item",content:s},{block:"main-ui-square-delete",mix:["main-ui-item-icon"]}]}}})();(function(){BX.namespace("BX.Main.ui.block");BX.Main.ui.block["number-group"]=function(e){var t,i,s,n,a;t={block:"main-ui-control-field-group",name:"name"in e?e.name+"_numsel":"",mix:"mix"in e?e.mix:null,attrs:{"data-type":"type"in e?e.type:"","data-name":"name"in e?e.name:""},content:[]};if("label"in e&&BX.type.isNotEmptyString(e.label)){var r=e.label;if("icon"in e&&BX.Type.isPlainObject(e.icon)){r=[{block:"main-ui-control-field-label-icon",tag:"img",attrs:{title:e.icon.title?e.icon.title:"",src:e.icon.url}},{block:"main-ui-control-field-label-text",tag:"span",content:r}]}n={block:"main-ui-control-field-label",tag:"span",attrs:{title:e.label},content:r};t.content.push(n)}i={block:"main-ui-control-field",dragButton:false,content:{block:"main-ui-select",tabindex:"tabindex"in e?e.tabindex:"",value:"value"in e?e.value:"",items:"items"in e?e.items:"",name:"name"in e?e.name+"_numsel":"",params:"params"in e?e.params:"",valueDelete:false}};t.content.push(i);if("content"in e&&BX.type.isArray(e.content)){e.content.forEach((function(e){t.content.push(e)}))}if("content"in e&&(BX.type.isPlainObject(e.content)||BX.type.isNotEmptyString(e.content))){t.content.push(e.content)}s={block:"main-ui-item-icon-container",content:{block:"main-ui-item-icon",mix:["main-ui-delete","main-ui-filter-field-delete"],tag:"span",attrs:{title:"deleteTitle"in e&&e.deleteTitle?e.deleteTitle:""}}};t.content.push(s);if(!("dragButton"in e)||e.dragButton!==false){a={block:"main-ui-filter-icon-grab",mix:["main-ui-item-icon"],tag:"span",attrs:{title:"dragTitle"in e&&e.dragTitle?e.dragTitle:""}};t.content.push(a)}return t}})();(function(){BX.namespace("BX.Main.ui.block");BX.Main.ui.block["sidebar-item"]=function(e){return{block:"main-ui-filter-sidebar-item"+("pinned"in e&&e.pinned?" main-ui-item-pin":""),attrs:{"data-id":"id"in e?e.id:""},content:[{block:"main-ui-filter-icon-grab",tag:"span",mix:["main-ui-item-icon"],attrs:{title:"dragTitle"in e&&e.dragTitle?e.dragTitle:""}},{block:"main-ui-filter-sidebar-item-text-container",tag:"span",content:[{block:"main-ui-filter-sidebar-item-input",tag:"input",attrs:{type:"text",placeholder:"placeholder"in e?e.placeholder:"",value:"text"in e?BX.util.htmlspecialchars(BX.util.htmlspecialcharsback(e.text)):""}},{block:"main-ui-filter-sidebar-item-text",tag:"span",content:"text"in e?e.text:"",attrs:{title:"text"in e?e.text:""}},{block:"main-ui-filter-icon-pin",tag:"span",mix:["main-ui-item-icon"],attrs:{title:"noEditPinTitle"in e&&e.noEditPinTitle?e.noEditPinTitle:""}}]},{block:"main-ui-filter-icon-edit",tag:"span",mix:["main-ui-item-icon"],attrs:{title:"editNameTitle"in e&&e.editNameTitle?e.editNameTitle:""}},{block:"main-ui-delete",tag:"span",mix:["main-ui-item-icon"],attrs:{title:"removeTitle"in e&&e.removeTitle?e.removeTitle:""}},{block:"main-ui-filter-icon-pin",tag:"span",mix:["main-ui-item-icon"],attrs:{title:"editPinTitle"in e&&e.editPinTitle?e.editPinTitle:""}},{block:"main-ui-filter-edit-mask"}]}}})();(function(){BX.namespace("BX.Filter");BX.Filter.Utils={cache:{},styleForEach:function e(t,i){var s;i=BX.type.isPlainObject(i)?i:null;s=Object.keys(i);[].forEach.call(t||[],(function(e){s.forEach((function(t){BX.style(e,t,i[t])}))}))},closestParent:function e(t,i){if(t){if(!i){return t.parentNode||null}else{return BX.findParent(t,{className:i})}}},closestChilds:function e(t){return!!t?t.children:null},getNext:function e(t){return!!t?t.nextElementSibling:null},getPrev:function e(t){return!!t?t.previousElementSibling:null},collectionSort:function e(t,i){var s,n,a,r,l;if(t&&i&&t!==i&&t.parentNode===i.parentNode){s=this.closestParent(i);n=this.closestChilds(s);a=n.length;r=this.getIndex(n,t);l=this.getIndex(n,i);if(a===l){s.appendChild(i)}if(r>l){s.insertBefore(t,i)}if(r<l&&a!==l){s.insertBefore(t,this.getNext(i))}}},getIndex:function e(t,i){return[].indexOf.call(t||[],i)},getByClass:function e(t,i,s){var n=[];if(i){n=(t||document.body).getElementsByClassName(i);if(!s){n=n.length?n[0]:null}else{n=[].slice.call(n)}}return n},getByTag:function e(t,i,s){var n=[];if(i){n=(t||document.body).getElementsByTagName(i);if(!s){n=n.length?n[0]:null}else{n=[].slice.call(n)}}return n},getBySelector:function e(t,i,s){var n=[];if(i){if(!s){n=(t||document.body).querySelector(i)}else{n=(t||document.body).querySelectorAll(i);n=[].slice.call(n)}}return n},requestAnimationFrame:function e(){var t=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||window.oRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)};t.apply(window,arguments)},sortObject:function e(t){var i={};Object.keys(t).sort().forEach((function(e){i[e]=t[e]}));return i},objectsIsEquals:function e(t,i){return JSON.stringify(t)===JSON.stringify(i)},isKey:function e(t,i){var s={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",27:"escape",32:"space",37:"leftArrow",38:"upArrow",39:"rightArrow",40:"downArrow",46:"delete",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",65:"a"};var n=!!t?"keyCode"in t?t.keyCode:"which"in t?t.which:0:0;return n in s&&s[n]===i}}})();(function(){BX.namespace("BX.Filter");BX.Filter.DestinationSelectorManager={fields:[],controls:{},onSelect:function e(t,i,s){if(!BX.type.isNotEmptyObject(s)||!BX.type.isNotEmptyObject(s.item)||!BX.type.isNotEmptyString(s.selectorId)){return}var n=s.selectorId,a=s.item;var r=BX.Filter.DestinationSelectorManager.controls[n];if(r){var l=a.id;if(BX.type.isNotEmptyString(t)&&t=="Y"&&BX.type.isNotEmptyString(i)){var o=new RegExp("^"+i+"(\\d+)$");var u=l.match(o);if(BX.type.isArray(u)){l=u[1]}}else{var c={};BX.onCustomEvent(window,"BX.Filter.DestinationSelector:convert",[{selectorId:n,value:l},c]);if(BX.type.isNotEmptyString(c.value)){l=c.value}}r.setData(BX.util.htmlspecialcharsback(a.name),l);r.getLabelNode().value="";r.getLabelNode().blur()}},onDialogOpen:function e(t){if(typeof t=="undefined"||!BX.type.isNotEmptyString(t.selectorId)){return}var i=t.selectorId;var s=BX.Filter.DestinationSelector.items[i];if(s){s.onDialogOpen()}},onDialogClose:function e(t){if(typeof t=="undefined"||!BX.type.isNotEmptyString(t.selectorId)){return}var i=t.selectorId;var s=BX.Filter.DestinationSelector.items[i];if(s){s.onDialogClose()}}};BX.Filter.DestinationSelector=function(){this.id="";this.filterId="";this.settings={};this.fieldId="";this.control=null;this.inited=null};BX.Filter.DestinationSelector.items={};BX.Filter.DestinationSelector.create=function(e,t){if(typeof this.items[e]!="undefined"){return this.items[e]}var i=new BX.Filter.DestinationSelector(e,t);i.initialize(e,t);this.items[e]=i;BX.onCustomEvent(window,"BX.Filter.DestinationSelector:create",[e]);return i};BX.Filter.DestinationSelector.prototype.getSetting=function(e,t){return this.settings.hasOwnProperty(e)?this.settings[e]:t};BX.Filter.DestinationSelector.prototype.getSearchInput=function(){return this.control?this.control.getLabelNode():null};BX.Filter.DestinationSelector.prototype.initialize=function(e,t){this.id=e;this.settings=t?t:{};this.fieldId=this.getSetting("fieldId","");this.filterId=this.getSetting("filterId","");this.inited=false;this.opened=null;var i=this.getSetting("initialValue",false);if(!!i){var s={};s[this.fieldId]=i.itemId;s[this.fieldId+"_label"]=i.itemName;BX.Main.filterManager.getById(this.filterId).getApi().setFields(s)}BX.addCustomEvent(window,"BX.Main.Filter:customEntityFocus",BX.delegate(this.onCustomEntitySelectorOpen,this));BX.addCustomEvent(window,"BX.Main.Filter:customEntityBlur",BX.delegate(this.onCustomEntitySelectorClose,this));BX.addCustomEvent(window,"BX.Main.Filter:onGetStopBlur",BX.delegate(this.onGetStopBlur,this));BX.addCustomEvent(window,"BX.Main.SelectorV2:beforeInitDialog",BX.delegate(this.onBeforeInitDialog,this));BX.addCustomEvent(window,"BX.Main.Filter:customEntityRemove",BX.delegate(this.onCustomEntityRemove,this))};BX.Filter.DestinationSelector.prototype.open=function(){var e=this.id;if(!this.inited){var t=this.getSearchInput();t.id=t.name;BX.addCustomEvent(window,"BX.Main.SelectorV2:afterInitDialog",BX.delegate((function(e){if(typeof e.id!="undefined"||e.id!=this.id){return}this.opened=true}),this));BX.addCustomEvent(window,"BX.UI.SelectorManager:onCreate",BX.delegate((function(e){if(!BX.type.isNotEmptyString(e)||e!=this.id){return}BX.onCustomEvent(window,"BX.Filter.DestinationSelector:setSelected",[{selectorId:e,current:this.control.getCurrentValues()}])}),this));BX.onCustomEvent(window,"BX.Filter.DestinationSelector:openInit",[{id:this.id,inputId:t.id,containerId:t.id}])}else{var i={};i[this.currentUser.entityId]="users";BX.onCustomEvent(window,"BX.Filter.DestinationSelector:open",[{id:this.id,bindNode:this.control.getField(),value:i}]);this.opened=true}};BX.Filter.DestinationSelector.prototype.close=function(){if(typeof BX.Main.selectorManagerV2.controls[this.id]!=="undefined"){BX.Main.selectorManagerV2.controls[this.id].closeDialog()}};BX.Filter.DestinationSelector.prototype.onCustomEntitySelectorOpen=function(e){var t=e.getId();if(this.fieldId!==t){this.control=null}else{this.control=e;if(this.control){var i=this.control.getCurrentValues();this.currentUser={entityId:i["value"]}}BX.Filter.DestinationSelectorManager.controls[this.id]=this.control;if(!this.opened){this.open()}else{this.close()}}};BX.Filter.DestinationSelector.prototype.onCustomEntitySelectorClose=function(e){if(this.fieldId===e.getId()&&this.inited===true&&this.opened===true){this.control=null;window.setTimeout(BX.delegate(this.close,this),0)}};BX.Filter.DestinationSelector.prototype.onGetStopBlur=function(e,t){if(BX.findParent(e.target,{className:"bx-lm-box"})){t.stopBlur=true}};BX.Filter.DestinationSelector.prototype.onCustomEntityRemove=function(e){if(this.fieldId===e.getId()){var t=BX.UI.SelectorManager.instances[e.getId()];if(t&&typeof e.hiddenInput!="undefined"&&typeof e.hiddenInput.value!="undefined"&&BX.type.isNotEmptyObject(t.itemsSelected)&&typeof t.itemsSelected[e.hiddenInput.value]!="undefined"){delete t.itemsSelected[e.hiddenInput.value]}}};BX.Filter.DestinationSelector.prototype.onBeforeInitDialog=function(e){if(typeof e.id=="undefined"||e.id!=this.id){return}this.inited=true;if(!this.control){e.blockInit=true}};BX.Filter.DestinationSelector.prototype.onDialogOpen=function(){this.opened=true};BX.Filter.DestinationSelector.prototype.onDialogClose=function(){this.opened=false}})();function a(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,s)}return i}function r(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?a(Object(i),!0).forEach((function(t){babelHelpers.defineProperty(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):a(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}var l=function(){function e(t,s){babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"id",null);babelHelpers.defineProperty(this,"filter",null);babelHelpers.defineProperty(this,"dialog",null);babelHelpers.defineProperty(this,"dialogOptions",null);babelHelpers.defineProperty(this,"control",null);babelHelpers.defineProperty(this,"isMultiple",false);babelHelpers.defineProperty(this,"needAddEntityIdToFilter",false);babelHelpers.defineProperty(this,"isActive",false);babelHelpers.defineProperty(this,"needShowDialogOnEmptyInput",true);this.id=t;this.settings=s?s:{};this.filter=this.getSetting("filter",null);if(!this.filter){throw new Error("Filter option is required for EntitySelector field")}this.isMultiple=!!this.getSetting("isMultiple",false);this.needAddEntityIdToFilter=this.getSetting("addEntityIdToResult","N")==="Y";this.needShowDialogOnEmptyInput=!!this.getSetting("showDialogOnEmptyInput",true);this.dialogOptions=this.prepareDialogOptions();this.dialog=null;i.EventEmitter.subscribe("BX.Main.Filter:customEntityFocus",this.onCustomEntityFocus.bind(this));i.EventEmitter.subscribe("BX.Main.Filter:customEntityBlur",this.onCustomEntityBlur.bind(this));i.EventEmitter.subscribe("BX.Main.Filter:onGetStopBlur",this.onGetStopBlur.bind(this));i.EventEmitter.subscribe("BX.Main.Filter:move",this.onCustomEntityRemove.bind(this));i.EventEmitter.subscribe("BX.Main.Filter:onApplyPreset",this.onApplyPreset.bind(this));this.controlInputChangeHandler=this.onSearchInputChange.bind(this)}babelHelpers.createClass(e,[{key:"open",value:function e(){var t=this;this.isActive=true;if(!this.dialog){this.initDialog().then((function(){if(t.isActive){t.openDialog()}}))}else{this.openDialog()}}},{key:"close",value:function e(){this.isActive=false;if(this.dialog&&this.dialog.isOpen()){this.dialog.hide()}}},{key:"getFilterField",value:function e(){return this.filter.getField(this.id)}},{key:"getFilterFieldInputWrapper",value:function e(){var t=this.getFilterField();if(!t){return null}return BX.Filter.Utils.getBySelector(t.node,".main-ui-control-entity")}},{key:"getFilterFieldInput",value:function e(){var t=this.getFilterField();if(!t){return null}return BX.Filter.Utils.getBySelector(t.node,"."+this.filter.settings.classStringInput+'[type="text"]')}},{key:"setControl",value:function e(t){this.control=t}},{key:"unsetControl",value:function e(){this.control=null}},{key:"getSetting",value:function e(t,i){return this.settings.hasOwnProperty(t)?this.settings[t]:i}},{key:"prepareDialogOptions",value:function e(){var t={enableSearch:false,hideOnSelect:true,autoHide:false,hideByEsc:false};var i=this.getSetting("dialogOptions",{});i=Object.assign(t,i);return i}},{key:"openDialog",value:function e(){if(this.dialog.isOpen()){return}var t=this.getFilterFieldInputWrapper();var i=this.getFilterFieldInput();var s=n.Type.isDomNode(i)?i.value.trim():"";this.dialog.setTargetNode(t);this.dialog.setWidth(t.offsetWidth);if(this.needShowDialogOnEmptyInput||s.length){this.dialog.show()}this.updateSelectedItemsInDialog(this.dialog);if(s.length){this.dialog.search(s)}}},{key:"initDialog",value:function t(){var s=this;return e.initDialogExtension().then((function(e){var t=e.Dialog;s.dialog=new t(r(r({},s.dialogOptions),{},{id:s.getDialogId(),multiple:s.isMultiple}));i.EventEmitter.subscribe(s.dialog,"Item:onSelect",s.onDialogItemSelect.bind(s));i.EventEmitter.subscribe(s.dialog,"Item:onDeselect",s.onDialogItemDeSelect.bind(s));i.EventEmitter.subscribe(s.dialog,"onLoad",s.onDialogLoad.bind(s));var a=s.getFilterFieldInput();n.Event.bind(a,"input",s.controlInputChangeHandler)}))}},{key:"addItemToFilter",value:function e(t,i){if(!this.control){return}if(this.isMultiple){var s=this.control.getCurrentValues();if(!s.filter((function(e){return e.value===t})).length){s.push({value:t,label:i});this.control.setMultipleData(s)}}else{this.control.setSingleData(i,t)}}},{key:"removeItemFromFilter",value:function e(t){if(!this.control){return}if(this.isMultiple){var i=this.control.getCurrentValues();this.control.setMultipleData(i.filter((function(e){return e.value!==t})))}else{this.control.clearValue()}}},{key:"getDialogId",value:function e(){return this.id+"_"+this.filter.getParam("FILTER_ID")}},{key:"getItemId",value:function e(t){if(this.needAddEntityIdToFilter){return JSON.stringify([t.getEntityId()+"",t.getId()+""])}return t.getId()+""}},{key:"updateSelectedItemsInDialog",value:function e(t){var i=this;if(!this.control){return}var s=this.control.getCurrentValues();if(!this.isMultiple){s=[s]}var n=s.map((function(e){return e.value}));t.getItems().forEach((function(e){if(n.indexOf(i.getItemId(e))>-1){e.select(true)}else{e.deselect()}}))}},{key:"onCustomEntityFocus",value:function e(t){var i=t.getData(),s=babelHelpers.slicedToArray(i,1),n=s[0];if(this.id!==n.getId()){return}this.setControl(n);this.open()}},{key:"onCustomEntityBlur",value:function e(t){var i=t.getData(),s=babelHelpers.slicedToArray(i,1),n=s[0];if(this.id!==n.getId()){return}this.close();this.unsetControl()}},{key:"onGetStopBlur",value:function e(t){var i=t.getData(),s=babelHelpers.slicedToArray(i,2),a=s[0],r=s[1];if(!(this.dialog&&this.dialog.isOpen())){return}var l=this.getFilterField();if(!l){return}var o=a.target;if(o===l.node||l.node.contains(o)&&!n.Dom.hasClass(o,this.filter.settings.classFieldDelete)||o===document.body){r.stopBlur=true;return}var u=this.dialog.getPopup().getContentContainer();if(o===u||u.contains(o)){r.stopBlur=true}}},{key:"onCustomEntityRemove",value:function e(t){var i=t.getData(),s=babelHelpers.slicedToArray(i,1),n=s[0];if(this.id!==n.getId()){return}if(this.dialog){this.dialog.destroy();this.dialog=null}this.unsetControl()}},{key:"onApplyPreset",value:function e(t){if(this.dialog){this.dialog.destroy();this.dialog=null}this.unsetControl()}},{key:"onSearchInputChange",value:function e(t){if(this.dialog){if(!this.needShowDialogOnEmptyInput){if(t.target.value){this.open()}else{this.close()}}this.dialog.search(t.target.value)}}},{key:"onDialogItemSelect",value:function e(t){var i=t.getData(),s=i.item;this.addItemToFilter(this.getItemId(s),s.getTitle());this.getFilterFieldInput().value=""}},{key:"onDialogItemDeSelect",value:function e(t){var i=t.getData(),s=i.item;this.removeItemFromFilter(this.getItemId(s))}},{key:"onDialogLoad",value:function e(t){var i=t.getTarget();this.updateSelectedItemsInDialog(i)}}],[{key:"initDialogExtension",value:function t(){if(!e.initExtensionPromise){e.initExtensionPromise=n.Runtime.loadExtension("ui.entity-selector")}return e.initExtensionPromise}},{key:"create",value:function t(i,s){if(n.Type.isObject(this.items[i])){if(n.Type.isObject(s.filter)){this.items[i].filter=s.filter}return this.items[i]}var a=new e(i,s);this.items[i]=a;return a}}]);return e}();babelHelpers.defineProperty(l,"initExtensionPromise",null);babelHelpers.defineProperty(l,"items",{});var o=n.Reflection.namespace("BX.Filter");o.EntitySelector=l;(function(){BX.namespace("BX.Filter");BX.Filter.FieldController=function(e,t){this.field=null;this.parent=null;this.type=null;this.input=null;this.deleteButton=null;this.init(e,t)};BX.Filter.FieldController.prototype={init:function e(t,i){if(!BX.type.isDomNode(t)){throw"BX.Filter.FieldController.init: field isn't dom node"}if(!(i instanceof BX.Main.Filter)){throw"BX.Filter.FieldController.init: parent not instance of BX.Main.ui.Filter"}this.field=t;this.parent=i;this.bind();this.isShowDelete()?this.showDelete():this.hideDelete()},isShowDelete:function e(){var t=this.getSquares();return this.getInputValue()||BX.type.isArray(t)&&t.length},getField:function e(){return this.field},getInput:function e(){var t,i;if(!BX.type.isDomNode(this.input)){t=this.getType();i=this.parent.types;if(t===i.DATE){this.input=BX.Filter.Utils.getByClass(this.getField(),this.parent.settings.classDateInput)}if(t===i.NUMBER||t==="number"){this.input=BX.Filter.Utils.getByClass(this.getField(),this.parent.settings.classNumberInput)}if(t===i.STRING){this.input=BX.Filter.Utils.getByClass(this.getField(),this.parent.settings.classStringInput)}if(t===i.CUSTOM_ENTITY){this.input=BX.Filter.Utils.getBySelector(this.getField(),'input[type="hidden"]')}}return this.input},getDeleteButton:function e(){if(!BX.type.isDomNode(this.deleteButton)){this.deleteButton=BX.Filter.Utils.getByClass(this.getField(),this.parent.settings.classValueDelete)}return this.deleteButton},getSquares:function e(){return BX.Filter.Utils.getByClass(this.getField(),this.parent.settings.classSquare)},bind:function e(){if(this.getType()!==this.parent.types.MULTI_SELECT&&this.getType()!==this.parent.types.SELECT){BX.bind(this.getDeleteButton(),"click",BX.delegate(this._onDeleteClick,this));BX.bind(this.getInput(),"input",BX.delegate(this._onInput,this))}},clearInput:function e(){var t=this.getInput();if(BX.type.isDomNode(t)){t.value=""}},hideDelete:function e(){var t=this.getDeleteButton();if(BX.type.isDomNode(t)){BX.addClass(t,this.parent.settings.classHide)}},showDelete:function e(){var t=this.getDeleteButton();if(BX.type.isDomNode(t)){BX.removeClass(t,this.parent.settings.classHide)}},removeSquares:function e(){var t=this.getSquares();if(BX.type.isArray(t)&&t.length){t.forEach((function(e){BX.remove(e)}))}},_onDeleteClick:function e(){this.removeSquares();this.clearInput();this.hideDelete()},_onInput:function e(){this.getInputValue()?this.showDelete():this.hideDelete()},getInputValue:function e(){var t="";var i=this.getInput();if(BX.type.isDomNode(i)){t=i.value}return t},getType:function e(){if(!BX.type.isNotEmptyString(this.type)){this.type=BX.data(this.getField(),"type")}return this.type}}})();(function(){BX.namespace("BX.Main.ui");BX.Main.ui.CustomEntity=function(){this.field=null;this.labelInput=null;this.hiddenInput=null;this.popupContainer=null;this.inputClass="main-ui-control-string";this.squareClass="main-ui-square";this.multiple=null};BX.Main.ui.CustomEntity.isMultiple=function(e){if(!!e&&!BX.hasClass(e,"main-ui-control-entity")){e=BX.Filter.Utils.getByClass(e,"main-ui-control-entity")}return!!e&&JSON.parse(BX.data(e,"multiple"))};BX.Main.ui.CustomEntity.prototype={setField:function e(t){if(this.field!==t){this.field=t;this.reset()}},isMultiple:function e(){return BX.Main.ui.CustomEntity.isMultiple(this.getField())},reset:function e(){this.labelInput=null;this.hiddenInput=null},getField:function e(){return this.field},getId:function e(){var t=this.getHiddenNode();var i=null;if(BX.type.isDomNode(t)){i=t.name}return i},getLabelNode:function e(){if(!BX.type.isDomNode(this.labelInput)){this.labelInput=BX.Filter.Utils.getBySelector(this.getField(),"."+this.inputClass+'[type="text"]')}return this.labelInput},getHiddenNode:function e(){if(!BX.type.isDomNode(this.hiddenInput)){this.hiddenInput=BX.Filter.Utils.getBySelector(this.getField(),"."+this.inputClass+'[type="hidden"]')}return this.hiddenInput},getSquareByValue:function e(t){return BX.Filter.Utils.getBySelector(this.getField(),['[data-item*=":'+BX.util.jsencode(t)+'}"]','[data-item*=":\\"'+BX.util.jsencode(t)+'\\"}"]'].join(", "))},getSquares:function e(){return BX.Filter.Utils.getByClass(this.getField(),this.squareClass,true)},removeSquares:function e(){this.getSquares().forEach(BX.remove)},setSquare:function e(t,i){var s=this.getField();var n={block:"main-ui-square",name:t,item:{_label:t,_value:i}};var a=BX.decl(n);var r=this.getSquares();if(!r.length){BX.prepend(a,s)}else{BX.insertAfter(a,r[r.length-1])}},getCurrentValues:function e(){var t=this.getSquares();var i,s;if(this.isMultiple()){s=[];for(var n=0,a=t.length;n<a;n++){try{i=JSON.parse(BX.data(t[n],"item"));s.push({label:i._label,value:i._value})}catch(e){}}}else{if(t.length===0){s={label:"",value:""}}else{try{i=JSON.parse(BX.data(t[0],"item"));s={label:i._label,value:i._value}}catch(e){s={label:"",value:""}}}}return s},setData:function e(t,i){return this.isMultiple()?this.setMultipleData(t,i):this.setSingleData(t,i)},setSingleData:function e(t,i){var s=this.getHiddenNode();this.removeSquares();this.setSquare(t,i);if(BX.type.isDomNode(s)){s.value=i;BX.fireEvent(s,"input")}},setMultipleData:function e(t,i){var s=[];var n=this.getHiddenNode();if(BX.type.isArray(t)){this.removeSquares();if(BX.type.isArray(t)){t.forEach((function(e){s.push(e.value);this.setSquare(e.label,e.value)}),this);if(BX.type.isDomNode(n)){n.value=JSON.stringify(s);BX.fireEvent(n,"input")}}}if(!BX.type.isArray(t)&&i!==null){if(!this.getSquareByValue(i)){this.setSquare(t,i);this.getSquares().forEach((function(e){var t=JSON.parse(BX.data(e,"item"));if(BX.type.isPlainObject(t)){s.push(t._value)}}));n.value=JSON.stringify(s);BX.fireEvent(n,"input")}}},clearValue:function e(){this.removeSquares();var t=this.getHiddenNode();t.value=this.isMultiple()?"[]":""},setPopupContainer:function e(t){if(BX.type.isDomNode(t)){this.popupContainer=t}},getPopupContainer:function e(){return this.popupContainer}}})();(function(){BX.namespace("BX.Filter");BX.Filter.Search=function(e){this.parent=null;this.container=null;this.input=null;this.preset=null;this.buttonsContainer=null;this.delay=800;this.timeout=null;this.init(e)};BX.Filter.Search.prototype={init:function e(t){this.parent=t;BX.bind(this.getInput(),"input",BX.delegate(this._onInputWithoutDebounce,this));if(this.parent.getParam("ENABLE_LIVE_SEARCH")){BX.bind(this.getInput(),"input",BX.debounce(this._onInput,this.delay,this))}BX.bind(this.getInput(),"keydown",BX.delegate(this._onKeyDown,this));BX.bind(this.getFindButton(),"click",BX.delegate(this._onSearchClick,this));BX.bind(this.getContainer(),"click",BX.delegate(this._onSearchContainerClick,this));this.removeAutofocus();this.firstInit=true},removeAutofocus:function e(){var t=this.getInput();if(!!t){t.blur();t.autofocus=null}},getFindButton:function e(){if(!BX.type.isDomNode(this.findButton)){this.findButton=BX.Filter.Utils.getByClass(this.getContainer(),this.parent.settings.classSearchButton)}return this.findButton},_onSearchClick:function e(){this.apply()},selectSquare:function e(t){!!t&&BX.addClass(t,this.parent.settings.classSquareSelected)},selectSquares:function e(){this.getSquares().forEach(this.selectSquare,this)},unselectSquare:function e(t){!!t&&BX.removeClass(t,this.parent.settings.classSquareSelected)},unselectSquares:function e(){this.getSquares().forEach(this.unselectSquare,this)},removeSquares:function e(){this.getSquares().forEach(this.removeSquare,this)},isSquaresSelected:function e(){var t=this.getSquares();return t.length&&t.every(this.isSquareSelected,this)},isSquareSelected:function e(t){return!!t&&BX.hasClass(t,this.parent.settings.classSquareSelected)},getLastSquare:function e(){var t=this.getSquares();return!!t?t[t.length-1]:null},isTextSelected:function e(){var t=this.getSearchString().length;var i=this.getInput();var s=i.selectionStart;var n=i.selectionEnd;return s===0&&n!==0&&n===t},isSelectionStart:function e(){var t=this.getInput();var i=t.selectionStart;var s=t.selectionEnd;return i===0&&s===0},isSquareRemoveButton:function e(t){return!!t&&BX.hasClass(t,this.parent.settings.classSquareDelete)},isClearButton:function e(t){return!!t&&BX.hasClass(t,this.parent.settings.classClearSearchValueButton)},getClearButton:function e(){return this.getContainer().querySelector("."+this.parent.settings.classClearSearchValueButton)},isSearchButton:function e(t){return!!t&&BX.hasClass(t,this.parent.settings.classSearchButton)},adjustFocus:function e(){if(!BX.browser.IsMobile()){var t=this.getInput();if(document.activeElement!==t&&window.scrollY<BX.pos(t).top){t.value=t.value;t.blur();t.focus()}}},findSquareByChild:function e(t){return BX.findParent(t,{className:this.parent.settings.classSquare},true,false)},getSquareData:function e(t){var i=BX.data(t,"item");return!!t&&!!i?JSON.parse(i):null},isSquareControl:function e(t){var i=this.getSquareData(t);return!!i&&(i.type==="control"||BX.type.isArray(i))},onPresetSquareRemove:function e(){var t=this.parent;var i=t.getPreset();var s=i.getCurrentPresetId();var n=t.getParam("RESET_TO_DEFAULT_MODE");var a=t.getParam("VALUE_REQUIRED");var r=i.isPinned(s);var l=this.getSquares();if(l.length===1){if(a&&r){this.parent.showPopup();this.adjustPlaceholder();this.parent.getPreset().deactivateAllPresets()}else{if(n&&r||!n){var o=true;this.lastPromise=t.resetFilter(o);t.closePopup()}}if(n&&!r){this.lastPromise=t.getPreset().applyPinnedPreset()}}if(l.length>1){var u=i.getPreset(i.getCurrentPresetId());var c=i.getPreset("tmp_filter");c.FIELDS=BX.clone(u.ADDITIONAL);u.ADDITIONAL=[];i.deactivateAllPresets();i.applyPreset("tmp_filter");t.applyFilter()}},onControlSquareRemove:function e(t){var i=this.parent;var s=i.getPreset();var n=i.getParam("RESET_TO_DEFAULT_MODE");var a=i.getParam("VALUE_REQUIRED");var r;if(n&&this.getSquares().length===1){if(a){r=this.getSquareData(t);i.clearControls(r);this.parent.showPopup();this.adjustPlaceholder();this.parent.getPreset().deactivateAllPresets()}else{this.lastPromise=i.getPreset().applyPinnedPreset()}}else{r=this.getSquareData(t);i.clearControls(r);i.closePopup();if(BX.type.isArray(r)){r.forEach((function(e){s.removeAdditionalField(e.name)}))}if(BX.type.isPlainObject(r)){s.removeAdditionalField(r.name)}this.apply()}},onValueRequiredSquareRemove:function e(){var t=this.parent;t.getPreset().deactivateAllPresets();t.showPopup();this.adjustPlaceholder()},complexSquareRemove:function e(t){var i=this.parent.getParam("VALUE_REQUIRED_MODE");var s=!this.isSquareControl(t);if(i){this.onValueRequiredSquareRemove()}else{if(s){this.onPresetSquareRemove()}else{this.onControlSquareRemove(t)}}this.removeSquare(t);this.adjustClearButton()},adjustClearButton:function e(){!!this.getLastSquare()?this.showClearButton():this.hideClearButton()},removeSquare:function e(t){!!t&&BX.remove(t)},_onSearchContainerClick:function e(t){var i=this.parent;if(this.isClearButton(t.target)){if(!i.getParam("VALUE_REQUIRED")){if(!i.getParam("VALUE_REQUIRED_MODE")){if(i.getParam("RESET_TO_DEFAULT_MODE")){this.clearInput();this.lastPromise=i.getPreset().applyPinnedPreset()}else{i.resetFilter()}i.closePopup();this.adjustFocus()}else{this.removeSquares();i.showPopup();this.adjustPlaceholder();this.hideClearButton();i.getPreset().deactivateAllPresets()}}else{var s=i.getPreset().isPinned(i.getPreset().getCurrentPresetId());if(s||i.getPreset().getCurrentPresetId()==="tmp_filter"){var n=i.getPreset().getPreset(i.getPreset().getCurrentPresetId());if(n.ADDITIONAL.length){n.ADDITIONAL=[];this.lastPromise=i.getPreset().applyPreset(i.getPreset().getCurrentPresetId());this.apply()}else{this.removeSquares();i.showPopup();this.adjustPlaceholder();this.hideClearButton();i.getPreset().deactivateAllPresets()}}else{if(i.getParam("RESET_TO_DEFAULT_MODE")){this.lastPromise=i.getPreset().applyPinnedPreset()}else{i.resetFilter()}i.closePopup();this.adjustFocus()}this.clearInput()}}else if(this.isSearchButton(t.target)){this.apply();this.adjustFocus()}else if(this.isSquareRemoveButton(t.target)){var a=this.findSquareByChild(t.target);this.complexSquareRemove(a);this.adjustFocus()}else{if(!i.getPopup().isShown()){i.showPopup()}else{var r=this.getInput();var l=r.selectionStart;var o=r.selectionEnd;var u=this.getSearchString().length;if(!(u&&l===0&&o===u)){if(i.getParam("VALUE_REQUIRED")){if(!this.getSquares().length){this.lastPromise=i.getPreset().applyPinnedPreset()}else{i.closePopup()}}else{i.closePopup();if(i.getParam("VALUE_REQUIRED_MODE")){i.restoreRemovedPreset()}}}}}},_onKeyDown:function e(t){var i=BX.Filter.Utils;var s=this.parent;if(i.isKey(t,"enter")){if(s.getParam("VALUE_REQUIRED")){if(!this.getSquares().length){this.parent.getPreset().applyPinnedPreset()}else{this.apply();this.firstInit=false;this.lastSearchString=this.getSearchString()}}else{this.apply();this.firstInit=false;this.lastSearchString=this.getSearchString()}s.closePopup()}if(i.isKey(t,"tab")||i.isKey(t,"downArrow")){s.showPopup();s.adjustFocus();this.unselectSquares()}if(i.isKey(t,"upArrow")){s.closePopup();if(s.getParam("VALUE_REQUIRED_MODE")){this.parent.restoreRemovedPreset()}if(s.getParam("VALUE_REQUIRED")){if(!this.getSquares().length){this.parent.getPreset().applyPinnedPreset()}}}if(i.isKey(t,"a")&&t.metaKey||i.isKey(t,"a")&&t.ctrlKey){this.selectSquares()}if(i.isKey(t,"backspace")&&this.isTextSelected()&&this.isSquaresSelected()){clearTimeout(this.timeout);if(this.parent.getParam("VALUE_REQUIRED")){var n=this.parent.getPreset().isPinned(this.parent.getPreset().getCurrentPresetId());if(n){this.removeSquares();this.parent.showPopup();this.adjustPlaceholder();this.hideClearButton();this.parent.getPreset().deactivateAllPresets()}else{if(this.parent.getParam("RESET_TO_DEFAULT_MODE")){this.lastPromise=this.parent.getPreset().applyPinnedPreset()}else{this.parent.resetFilter()}this.parent.closePopup();this.adjustFocus()}this.clearInput()}else{if(this.parent.getParam("RESET_TO_DEFAULT_MODE")){this.lastPromise=this.parent.getPreset().applyPinnedPreset()}else{this.lastPromise=this.parent.resetFilter()}this.parent.closePopup()}}if(i.isKey(t,"backspace")&&this.isSelectionStart()){clearTimeout(this.timeout);var a=this.getLastSquare();this.isSquareSelected(a)?this.complexSquareRemove(a):this.selectSquare(a)}if(!i.isKey(t,"backspace")&&!t.metaKey&&this.isSquaresSelected()){this.unselectSquares()}},getSearchString:function e(){var t=this.getInput();return!!t?t.value:""},getSquares:function e(){return BX.Filter.Utils.getByClass(this.getContainer(),this.parent.settings.classSquare,true)},adjustPlaceholder:function e(){if(this.parent.getParam("LIMITS_ENABLED")){this.setInputPlaceholder(this.parent.getParam("MAIN_UI_FILTER__PLACEHOLDER_LIMITS_EXCEEDED"))}else if(this.parent.getParam("DISABLE_SEARCH")||!this.parent.settings.get("SEARCH")){this.setInputPlaceholder(this.parent.getParam("MAIN_UI_FILTER__PLACEHOLDER"))}else{this.setInputPlaceholder(this.parent.getParam("MAIN_UI_FILTER__PLACEHOLDER_DEFAULT"))}},isResolvedRequest:function e(){return!this.lastPromise||!!this.lastPromise&&this.lastPromise.state},apply:function e(){if(this.isResolvedRequest()){this.lastPromise=this.parent._onFindButtonClick()}return this.lastPromise},reset:function e(){if(this.isResolvedRequest()){this.parent.getSearch().removePreset();this.parent.getPreset().deactivateAllPresets();this.parent.getPreset().resetPreset(true);this.timeout=setTimeout(BX.delegate((function(){this.lastPromise=this.parent.resetFilter()}),this),this.delay)}return this.lastPromise},_onInputWithoutDebounce:function e(){clearTimeout(this.timeout);var t=this.getSearchString();this.lastSearchString=!!this.lastSearchString?this.lastSearchString:t;if(t!==this.lastSearchString&&(!this.parent.isIe()||!this.firstInit)){if(this.parent.getParam("ENABLE_LIVE_SEARCH")){this.parent.showGridAnimation();BX.onCustomEvent(window,"BX.Filter.Search:input",[this.parent.params.FILTER_ID,t])}this.parent.getPopup().isShown()&&this.parent.closePopup()}if(t){this.showClearButton();this.parent.setIsSetOutsideState(false);this.parent.setDefaultPresetAppliedState(false)}else{if(!this.getSquares().length&&this.lastSearchString!==t){this.hideClearButton();this.adjustPlaceholder()}if(this.parent.isAppliedDefaultPreset()){this.parent.setDefaultPresetAppliedState(true)}}if(this.parent.isAppliedUserFilter()){BX.Dom.addClass(this.container,"main-ui-filter-search--active")}else{BX.Dom.removeClass(this.container,"main-ui-filter-search--active")}},_onInput:function e(){var t=this.getSearchString();if(t!==this.lastSearchString&&(!this.parent.isIe()||!this.firstInit)){this.apply()}this.firstInit=false;this.lastSearchString=t},getButtonsContainer:function e(){if(!BX.type.isDomNode(this.buttonsContainer)){this.buttonsContainer=BX.Filter.Utils.getByClass(this.getContainer(),this.parent.settings.classSearchButtonsContainer)}return this.buttonsContainer},showClearButton:function e(){BX.addClass(this.getButtonsContainer(),this.parent.settings.classShow)},hideClearButton:function e(){BX.removeClass(this.getButtonsContainer(),this.parent.settings.classShow)},getInput:function e(){var t;if(!BX.type.isDomNode(this.input)){t=[this.parent.getParam("FILTER_ID",""),"_search"].join("");this.input=BX(t)}return this.input},getContainer:function e(){var t;if(!BX.type.isDomNode(this.container)){t=[this.parent.getParam("FILTER_ID"),"_search_container"].join("");this.container=BX(t)}return this.container},setInputPlaceholder:function e(t){var i=this.getInput();i.placeholder=t},clearInput:function e(){var t=this.getInput();if(BX.type.isDomNode(t)){t.value=null}},clearForm:function e(){this.clearInput();this.removePreset()},makeSquares:function e(t,i,s){var n;var a=null;var r=this.getContainer();var l={squares:[],moreSquares:[]};t.forEach((function(e,t){if(t<i){n=BX.decl(e);a=a||n;if(!s){if(t===0){BX.prepend(n,r)}else{BX.insertAfter(n,a)}}else{var o=BX.Filter.Utils.getByClass(this.getContainer(),this.parent.settings.classSquare);if(o){BX.insertAfter(n,o)}else{BX.prepend(n,r)}}a=n;l.squares.push(n)}else{l.moreSquares.push({type:"control",name:e.value,title:e.title,icon:e.icon})}}),this);return l},squares:function e(t,i,s){var n,a,r,l,o;var e=BX.Filter.Utils.getByClass(this.getContainer(),this.parent.settings.classSquare,true);if(s){e.forEach((function(e){var t=BX.data(e,"item");if(t){BX.remove(e)}}))}else{e.forEach(BX.remove)}n=this.prepareSquaresData(t);a=this.makeSquares(n,i,s);l=0;o={squaresData:n,width:0};if(a.moreSquares.length){r={block:"main-ui-search-square",name:this.parent.getParam("MAIN_UI_FILTER__AND")+" "+this.parent.getParam("MAIN_UI_FILTER__MORE")+" "+a.moreSquares.length,item:a.moreSquares,title:a.moreSquares.map((function(e){var t=e.title;if("icon"in e&&BX.Type.isPlainObject(e.icon)){var i=e.icon.title;t=t.length?i+": "+t:""}return t})).join(", \n")};r=BX.decl(r);a.squares.push(r);BX.insertAfter(r,a.squares[a.squares.length-2]);l=a.squares.reduce((function(e,t){return e+BX.width(t)+(parseFloat(BX.style(t,"margin-right"))||0)}),0)}o.width=l;return o},setPreset:function e(t){var i=this.getContainer();var s,n;var a;if(BX.type.isPlainObject(t)){n=BX.Filter.Utils.getByClass(i,this.parent.settings.classSquare,true);n.forEach(BX.remove);t=BX.clone(t);t.ADDITIONAL=t.ADDITIONAL||[];BX.onCustomEvent(window,"BX.Filter.Search:beforeSquaresUpdate",[t,this]);if(t.ID!=="default_filter"&&t.ID!=="tmp_filter"){s=BX.decl({block:"main-ui-search-square",name:t.TITLE,value:t.ID,isPreset:true});BX.prepend(s,i);if("ADDITIONAL"in t&&BX.type.isArray(t.ADDITIONAL)&&t.ADDITIONAL.length){a=this.squares(t.ADDITIONAL,1,true);if(BX.width(i)-a.width<100){a=this.squares(t.ADDITIONAL,0,true)}}}else{if("ADDITIONAL"in t&&BX.type.isArray(t.ADDITIONAL)&&t.ADDITIONAL.length){t.ADDITIONAL.forEach((function(e,i){if(!("ID"in e)){e.ID="ADDITIONAL_ID_"+i}if(!("NAME"in e)){e.NAME="ADDITIONAL_NAME_"+i}if(!("TYPE"in e)){e.TYPE="STRING"}if("LABEL"in e&&"LABEL"in e){t.FIELDS.push(e)}}))}if(BX.type.isArray(t.FIELDS)&&t.FIELDS.length){a=this.squares(t.FIELDS,2);if(BX.width(i)-a.width<100){a=this.squares(t.FIELDS,1)}}}if(a&&BX.type.isArray(a.squaresData)&&a.squaresData.length||t.ID!=="default_filter"&&t.ID!=="tmp_filter"){if(this.parent.getParam("LIMITS_ENABLED")){this.setInputPlaceholder(this.parent.getParam("MAIN_UI_FILTER__PLACEHOLDER_LIMITS_EXCEEDED"))}else{this.setInputPlaceholder(this.parent.getParam("MAIN_UI_FILTER__PLACEHOLDER_WITH_FILTER"))}this.showClearButton()}else{this.adjustPlaceholder()}if(BX.type.isNotEmptyString(this.parent.getSearch().getInput().value)){this.showClearButton()}}},prepareSquaresData:function e(t){var i,s,n;var a=[];t=t.filter((function(e){return!!e&&this.parent.params.FIELDS.some((function(t){return e.NAME===t.NAME}))}),this);t.map((function(e){i=null;if(!BX.Type.isStringFilled(e.ADDITIONAL_FILTER)){switch(e.TYPE){case this.parent.types.DATE:{i=e.LABEL+": "+e.SUB_TYPE.NAME;if(e.SUB_TYPE.VALUE===this.parent.dateTypes.QUARTER&&BX.type.isNotEmptyString(e.VALUES._quarter)){var t=e.QUARTERS.filter((function(t){return t.VALUE==e.VALUES._quarter})).map((function(e){return e.NAME}));t=t.length?t.join(""):"";i=e.LABEL+": "+t+" "+this.parent.getParam("MAIN_UI_FILTER__QUARTER").toLocaleLowerCase()+" "+e.VALUES._year}if(e.SUB_TYPE.VALUE===this.parent.dateTypes.YEAR&&BX.type.isNotEmptyString(e.VALUES._year)){i=e.LABEL+": "+e.VALUES._year}if(e.SUB_TYPE.VALUE===this.parent.dateTypes.MONTH&&BX.type.isNotEmptyString(e.VALUES._month)){var r=e.MONTHS.filter((function(t){return t.VALUE==e.VALUES._month})).map((function(e){return e.NAME}));r=r.length?r.join(""):"";i=e.LABEL+": "+r+" "+e.VALUES._year}if(e.SUB_TYPE.VALUE===this.parent.dateTypes.EXACT&&BX.type.isNotEmptyString(e.VALUES._from)){i=e.LABEL+": "+e.VALUES._from}if(e.SUB_TYPE.VALUE===this.parent.dateTypes.RANGE){if(BX.type.isNotEmptyString(e.VALUES._from)&&BX.type.isNotEmptyString(e.VALUES._to)){i=e.LABEL+": "+e.VALUES._from+"-"+e.VALUES._to}else if(!BX.type.isNotEmptyString(e.VALUES._from)&&BX.type.isNotEmptyString(e.VALUES._to)){i=e.LABEL+": "+this.parent.getParam("MAIN_UI_FILTER__BEFORE")+" "+e.VALUES._to}else if(BX.type.isNotEmptyString(e.VALUES._from)&&!BX.type.isNotEmptyString(e.VALUES._to)){i=e.LABEL+": "+this.parent.getParam("MAIN_UI_FILTER__AFTER")+" "+e.VALUES._from}}if((e.SUB_TYPE.VALUE===this.parent.dateTypes.NEXT_DAYS||e.SUB_TYPE.VALUE===this.parent.dateTypes.PREV_DAYS)&&!BX.type.isNumber(parseInt(e.VALUES._days))){i=null}if(e.SUB_TYPE.VALUE===this.parent.dateTypes.NEXT_DAYS&&BX.type.isNumber(parseInt(e.VALUES._days))){i=e.LABEL+": "+this.parent.getParam("MAIN_UI_FILTER__DATE_NEXT_DAYS_LABEL").replace("#N#",e.VALUES._days)}if(e.SUB_TYPE.VALUE===this.parent.dateTypes.PREV_DAYS&&BX.type.isNumber(parseInt(e.VALUES._days))){i=e.LABEL+": "+this.parent.getParam("MAIN_UI_FILTER__DATE_PREV_DAYS_LABEL").replace("#N#",e.VALUES._days)}if(e.SUB_TYPE.VALUE===this.parent.dateTypes.NONE){i=null}break}case this.parent.types.CUSTOM_DATE:{if(BX.type.isArray(e.VALUE.days)&&e.VALUE.days.length||BX.type.isArray(e.VALUE.months)&&e.VALUE.months.length||BX.type.isArray(e.VALUE.years)&&e.VALUE.years.length){i=e.LABEL}break}case this.parent.types.SELECT:{if(BX.type.isPlainObject(e.VALUE)&&e.VALUE.VALUE||e.STRICT){i=e.LABEL+": "+e.VALUE.NAME}break}case this.parent.types.MULTI_SELECT:{if(BX.type.isArray(e.VALUE)&&e.VALUE.length){s=[];i=e.LABEL+": ";e.VALUE.forEach((function(e,t){if(t<2){s.push(e.NAME)}}));i+=s.join(", ");if(e.VALUE.length>2){n=[];e.VALUE.forEach((function(e){n.push(e.NAME)}));i=n.join(", ")}}break}case this.parent.types.NUMBER:{if(e.SUB_TYPE.VALUE==="exact"){if(BX.type.isNotEmptyString(e.VALUES._from)){i=e.LABEL+": "+e.VALUES._from}else{i=null}}if(e.SUB_TYPE.VALUE==="range"){if(BX.type.isNotEmptyString(e.VALUES._from)&&BX.type.isNotEmptyString(e.VALUES._to)){i=e.LABEL+": "+e.VALUES._from+"-"+e.VALUES._to}else if(!BX.type.isNotEmptyString(e.VALUES._from)&&BX.type.isNotEmptyString(e.VALUES._to)){i=e.LABEL+": "+this.parent.getParam("MAIN_UI_FILTER__NUMBER_LESS")+" "+e.VALUES._to}else if(BX.type.isNotEmptyString(e.VALUES._from)&&!BX.type.isNotEmptyString(e.VALUES._to)){i=e.LABEL+": "+this.parent.getParam("MAIN_UI_FILTER__NUMBER_MORE")+" "+e.VALUES._from}else{i=null}}if(e.SUB_TYPE.VALUE==="more"){if(BX.type.isNotEmptyString(e.VALUES._from)){i=e.LABEL+": > ";i+=e.VALUES._from}}if(e.SUB_TYPE.VALUE==="less"){if(BX.type.isNotEmptyString(e.VALUES._to)){i=e.LABEL+": < ";i+=e.VALUES._to}}if(e.SUB_TYPE.VALUE==="before_n"){if(BX.type.isNotEmptyString(e.VALUES._to)){i=e.LABEL+": < ";i+=e.VALUES._to}}break}case this.parent.types.CUSTOM_ENTITY:case this.parent.types.DEST_SELECTOR:case this.parent.types.ENTITY_SELECTOR:{if(e.MULTIPLE){var l=!!e.VALUES._label?e.VALUES._label:[];if(BX.type.isPlainObject(l)){l=Object.keys(l).map((function(e){return l[e]}))}if(!BX.type.isArray(l)){l=[l]}if(l.length>0){i=e.LABEL+": ";i+=l.join(", ")}}else{if(BX.type.isNotEmptyString(e.VALUES._value)&&BX.type.isNotEmptyString(e.VALUES._label)){i=e.LABEL+": ";i+=e.VALUES._label}}break}case this.parent.types.CUSTOM:{i="_VALUE"in e&&BX.type.isNotEmptyString(e._VALUE)?e.LABEL:null;break}default:{if(BX.type.isNotEmptyString(e.VALUE)){i=e.LABEL+": "+e.VALUE}break}}}else{var o={block:"main-ui-search-square",name:e.LABEL+": "+BX.Loc.getMessage("MAIN_UI_FILTER__ADDITIONAL_FILTER_PLACEHOLDER_IS_EMPTY"),value:e.NAME,icon:"ICON"in e?e.ICON:null,item:{type:"control",name:e.NAME},title:e.LABEL+": "+BX.Loc.getMessage("MAIN_UI_FILTER__ADDITIONAL_FILTER_PLACEHOLDER_IS_EMPTY")};if(e.ADDITIONAL_FILTER===BX.Filter.AdditionalFilter.Type.HAS_ANY_VALUE){o.name=e.LABEL+": "+BX.Loc.getMessage("MAIN_UI_FILTER__ADDITIONAL_FILTER_PLACEHOLDER_HAS_ANY_VALUE");o.title=e.LABEL+": "+BX.Loc.getMessage("MAIN_UI_FILTER__ADDITIONAL_FILTER_PLACEHOLDER_HAS_ANY_VALUE")}a.push(o)}if(i!==null){a.push({block:"main-ui-search-square",name:i,value:e.NAME,icon:"ICON"in e?e.ICON:null,item:{type:"control",name:e.NAME},title:i})}}),this);return a},getPreset:function e(){var t=this.getContainer();var i=this.parent.settings.classSquare;var s=null;if(BX.type.isDomNode(t)){s=BX.Filter.Utils.getByClass(t,i)}return s},removePreset:function e(){var t=this.getPreset();if(BX.type.isDomNode(t)){BX.remove(t);this.adjustPlaceholder()}this.hideClearButton()},updatePreset:function e(t){this.removePreset();this.setPreset(t)}}})();(function(){BX.namespace("BX.Filter");BX.Filter.Settings=function(e,t){this.classField="main-ui-control-field";this.classFieldGroup="main-ui-control-field-group";this.classFieldLine="main-ui-filter-field-line";this.classFieldDelete="main-ui-filter-field-delete";this.classFieldLabel="main-ui-control-field-label";this.classFieldWithLabel="main-ui-filter-wield-with-label";this.classPresetName="main-ui-filter-sidebar-item-text";this.classControl="main-ui-control";this.classDateInput="main-ui-date-input";this.classHide="main-ui-hide";this.classNumberInput="main-ui-number-input";this.classSelect="main-ui-select";this.classMultiSelect="main-ui-multi-select";this.classValueDelete="main-ui-control-value-delete";this.classStringInput="main-ui-control-string";this.classAddField="main-ui-filter-field-add-item";this.classAddPresetField="main-ui-filter-new-filter";this.classAddPresetFieldInput="main-ui-filter-sidebar-edit-control";this.classAddPresetButton="main-ui-filter-add-item";this.classButtonsContainer="main-ui-filter-field-button-container";this.classSaveButton="main-ui-filter-save";this.classCancelButton="main-ui-filter-cancel";this.classMenuItem="main-ui-select-inner-item";this.classMenuItemText="main-ui-select-inner-item-element";this.classMenuMultiItemText="main-ui-select-inner-label";this.classMenuItemChecked="main-ui-checked";this.classSearchContainer="main-ui-filter-search";this.classDefaultPopup="popup-window";this.classPopupFieldList="main-ui-filter-popup-field-list";this.classPopupFieldList1Column="main-ui-filter-field-list-1-column";this.classPopupFieldList2Column="main-ui-filter-field-list-2-column";this.classPopupFieldList3Column="main-ui-filter-field-list-3-column";this.classPopupFieldList4Column="main-ui-filter-field-list-4-column";this.classPopupFieldList5Column="main-ui-filter-field-list-5-column";this.classPopupFieldList6Column="main-ui-filter-field-list-6-column";this.classFieldListItem="main-ui-filter-field-list-item";this.classEditButton="main-ui-filter-add-edit";this.classPresetEdit="main-ui-filter-edit";this.classPresetNameEdit="main-ui-filter-edit-text";this.classPresetDeleteButton="main-ui-delete";this.classPresetDragButton="main-ui-filter-icon-grab";this.classPresetEditButton="main-ui-filter-icon-edit";this.classPresetEditInput="main-ui-filter-sidebar-item-input";this.classPresetOndrag="main-ui-filter-sidebar-item-ondrag";this.classSquare="main-ui-square";this.classSquareDelete="main-ui-square-delete";this.classSquareSelected="main-ui-square-selected";this.classPresetsContainer="main-ui-filter-sidebar-item-container";this.classPreset="main-ui-filter-sidebar-item";this.classPresetCurrent="main-ui-filter-current-item";this.classFilterContainer="main-ui-filter-wrapper";this.classFileldControlList="main-ui-filter-field-container-list";this.classRestoreFieldsButton="main-ui-filter-field-restore-items";this.classClearSearchValueButton="main-ui-delete";this.classSearchButtonsContainer="main-ui-item-icon-block";this.classSearchButton="main-ui-search";this.classDisabled="main-ui-disable";this.classAnimationShow="main-ui-popup-show-animation";this.classAnimationClose="main-ui-popup-close-animation";this.classLimitsAnimation="main-ui-filter-field-limits-animate";this.classSidebarControlsContainer="main-ui-filter-add-container";this.searchContainerPostfix="_search_container";this.classPresetButtonsContainer="main-ui-filter-field-preset-button-container";this.classFindButton="main-ui-filter-find";this.classResetButton="main-ui-filter-reset";this.classDefaultFilter="main-ui-filter-default-preset";this.classRestoreButton="main-ui-filter-reset-link";this.classPinButton="main-ui-filter-icon-pin";this.classPopupOverlay="popup-window-overlay";this.classSidePanelContainer="side-panel-container";this.classPinnedPreset="main-ui-item-pin";this.classWaitButtonClass="ui-btn-clock";this.classForAllCheckbox="main-ui-filter-save-for-all";this.classShow="main-ui-show";this.classFocus="main-ui-focus";this.classPresetField="main-ui-filter-preset-field";this.classPopupSearchFieldListItemHidden="main-ui-filter-field-list-item-hidden";this.classPopupSearchFieldListItemVisible="main-ui-filter-field-list-item-visible";this.classPopupSearchSectionItem="main-ui-filter-popup-search-section-input";this.classPopupSearchSectionItemIcon="main-ui-filter-popup-search-section-item-icon";this.classPopupSearchSectionItemIconActive="main-ui-filter-popup-search-section-item-icon-active";this.numberPostfix="_numsel";this.datePostfix="_datesel";this.toPostfix="_to";this.fromPostfix="_from";this.daysPostfix="_days";this.monthPostfix="_month";this.quarterPostfix="_quarter";this.yearPostfix="_year";this.generalTemplateId="";this.maxPopupColumnCount=6;this.popupWidth=630;this.init(e,t)};BX.Filter.Settings.prototype={init:function e(t,i){this.generalTemplateId=i.getParam("FILTER_ID")+"_GENERAL_template";this.mergeSettings(t)},get:function e(t,i){return t&&t in this&&!BX.type.isFunction(this[t])?this[t]:i},mergeSettings:function e(t){if(BX.type.isPlainObject(t)){Object.keys(t).forEach((function(e){if(!BX.type.isFunction(this[e])){this[e]=t[e]}}),this)}}}})();var u,c,d,h,p,f,m,E;function g(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,s)}return i}function y(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?g(Object(i),!0).forEach((function(t){babelHelpers.defineProperty(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):g(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}(function(){BX.namespace("BX.Main");BX.Main.Filter=function(e,t,i,s,n,a,r){this.params=e;this.search=null;this.popup=null;this.presets=null;this.fields=null;this.types=i;this.dateTypes=s;this.additionalDateTypes=a;this.additionalNumberTypes=r;this.numberTypes=n;this.settings=new BX.Filter.Settings(t,this);this.filter=null;this.api=null;this.isAddPresetModeState=false;this.firstInit=true;this.analyticsLabel=null;this.emitter=new BX.Event.EventEmitter;this.emitter.setEventNamespace("BX.Filter.Field");this.emitter.subscribe=function(e,t){BX.Event.EventEmitter.subscribe(this.emitter,e.replace("BX.Filter.Field:",""),t)}.bind(this);this.enableFieldsSearch=null;this.enableHeadersSections=null;this.init()};function e(e){if(BX.type.isString(e)){e=e.toLowerCase();e=e.replace(/[\-_\s]+(.)?/g,(function(e,t){return t?t.toUpperCase():""}));return e.substr(0,1).toLowerCase()+e.substr(1)}return e}BX.Main.Filter.prototype={init:function e(){BX.bind(document,"mousedown",BX.delegate(this._onDocumentClick,this));BX.bind(document,"keydown",BX.delegate(this._onDocumentKeydown,this));BX.bind(window,"load",BX.delegate(this.onWindowLoad,this));BX.addCustomEvent("Grid::ready",BX.delegate(this._onGridReady,this));this.getSearch().updatePreset(this.getParam("CURRENT_PRESET"));this.enableFieldsSearch=this.getParam("ENABLE_FIELDS_SEARCH",false);this.enableHeadersSections=this.getParam("HEADERS_SECTIONS",false);if(this.isAppliedDefaultPreset()){this.setDefaultPresetAppliedState(true)}},getEmitter:function e(){return this.emitter},onWindowLoad:function e(){this.settings.get("AUTOFOCUS")&&this.adjustFocus()},clearGet:function e(){if("history"in window){var t=window.location.toString();var i=BX.util.remove_url_param(t,"apply_filter");window.history.replaceState(null,"",i)}},adjustFocus:function e(){this.getSearch().adjustFocus()},_onAddPresetKeydown:function e(t){if(BX.Filter.Utils.isKey(t,"enter")){this._onSaveButtonClick()}},_onDocumentKeydown:function e(t){if(BX.Filter.Utils.isKey(t,"escape")){if(this.getPopup().isShown()){BX.onCustomEvent(window,"BX.Main.Filter:blur",[this]);this.closePopup();if(this.getParam("VALUE_REQUIRED_MODE")){this.restoreRemovedPreset()}if(this.getParam("VALUE_REQUIRED")){if(!this.getSearch().getSquares().length){this.getPreset().applyPinnedPreset()}}}}},getApi:function e(){if(!(this.api instanceof BX.Filter.Api)){this.api=new BX.Filter.Api(this)}return this.api},addSidebarItem:function e(t,i,s){var n=this.getPreset();var a=n.getContainer();var r=n.createSidebarItem(t,i,s);var l=n.getPresetNodeById(t);if(BX.type.isDomNode(l)){BX.remove(l);a.insertBefore(r,n.getAddPresetField())}else{a&&a.insertBefore(r,n.getAddPresetField())}BX.bind(r,"click",BX.delegate(n._onPresetClick,n))},saveUserSettings:function e(t){var i={FILTER_ID:this.getParam("FILTER_ID"),GRID_ID:this.getParam("GRID_ID"),action:"SET_FILTER_ARRAY"};var s=this.getPreset();var n=s.getCurrentPresetId();var a={};this.params["PRESETS"]=BX.clone(this.editablePresets);a.current_preset=n;s.getPresets().forEach((function(e,i){var n=s.getPresetId(e);if(n&&n!=="tmp_filter"){var r=s.getPreset(n);r.TITLE=BX.util.htmlspecialchars(BX.util.htmlspecialcharsback(r.TITLE));r.SORT=i;s.updatePresetName(e,r.TITLE);a[n]={sort:i,name:r.TITLE,fields:this.preparePresetSettingsFields(r.FIELDS),rows:r.FIELDS.map((function(e){return e.NAME})),for_all:t&&!BX.type.isBoolean(r.FOR_ALL)||t&&r.FOR_ALL===true}}}),this);this.saveOptions(a,i,null,t)},isForAll:function e(t){var i=this.getForAllCheckbox();return BX.type.isBoolean(t)&&t||!!i&&!!i.checked},getForAllCheckbox:function e(){if(!this.forAllCheckbox){this.forAllCheckbox=BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classForAllCheckbox)}return this.forAllCheckbox},preparePresetSettingsFields:function e(t){var i={};var s;(t||[]).forEach((function(e){switch(e.TYPE){case this.types.STRING:{i[e.NAME]=e.VALUE;break}case this.types.TEXTAREA:{i[e.NAME]=e.VALUE;break}case this.types.SELECT:{i[e.NAME]="VALUE"in e.VALUE?e.VALUE.VALUE:"";break}case this.types.MULTI_SELECT:{if(BX.type.isArray(e.VALUE)&&e.VALUE.length){e.VALUE.forEach((function(t,s){i[e.NAME]=BX.type.isPlainObject(i[e.NAME])?i[e.NAME]:{};i[e.NAME][s]=t.VALUE}),this)}break}case this.types.CHECKBOX:{if(BX.type.isArray(e.VALUE)&&e.VALUE.length){e.VALUE.forEach((function(t,s){i[e.NAME]=BX.type.isPlainObject(i[e.NAME])?i[e.NAME]:{};i[e.NAME][s]=t.VALUE}),this)}break}case this.types.DATE:{if(BX.type.isPlainObject(e.VALUES)){s=Object.keys(e.VALUES);i[e.NAME+"_datesel"]=e.SUB_TYPE.VALUE;s.forEach((function(t){i[e.NAME+t]=e.VALUES[t]}),this)}break}case this.types.NUMBER:{if(BX.type.isPlainObject(e.VALUES)){s=Object.keys(e.VALUES);i[e.NAME+"_numsel"]=e.SUB_TYPE.VALUE;s.forEach((function(t){i[e.NAME+t]=e.VALUES[t]}),this)}break}case this.types.DEST_SELECTOR:{if(BX.type.isPlainObject(e.VALUES)){i[e.NAME]=e.VALUES._value;i[e.NAME+"_label"]=e.VALUES._label}break}case this.types.DEST_SELECTOR:case this.types.ENTITY_SELECTOR:case this.types.CUSTOM_ENTITY:{if(BX.type.isPlainObject(e.VALUES)){i[e.NAME]=e.VALUES._value;i[e.NAME+"_label"]=e.VALUES._label}break}default:{break}}}),this);return i},savePreset:function e(){var t="filter_"+ +new Date;var i=BX.util.htmlspecialcharsback(this.getPreset().getAddPresetFieldInput().value);this.updatePreset(t,i,null,true,null,null,true);this.addSidebarItem(t,i);this.getPreset().applyPreset(t);this.getPreset().activatePreset(t);this.applyFilter()},updatePreset:function e(t,i,s,n,a,r,l){var o=this.getFilterFieldsValues();var u=this.getPreset().getFields().map((function(e){return BX.data(e,"name")}));var c=this.getPreset().getCurrentPresetData();var d={FILTER_ID:this.getParam("FILTER_ID"),GRID_ID:this.getParam("GRID_ID"),action:"SET_FILTER"};var h,p,f,m,E;var g={};g.additional={};if(t!=="tmp_filter"&&t!=="default_filter"&&!l){var y=BX.type.isArray(c.ADDITIONAL)?c.ADDITIONAL:[];y.forEach((function(e){Object.keys(o).forEach((function(t){if(t.indexOf(e.NAME)!==-1){g.additional[t]=o[t];delete o[t]}}))}))}h=Object.keys(o);if(!s){g.apply_filter="Y"}else{g.clear_filter="Y"}g.save="Y";g.fields=o;g.rows=u.join(",");g.preset_id=t||c.ID;if(BX.type.isNotEmptyString(i)){g.name=BX.util.htmlspecialchars(i)}else{f=this.getPreset().getPresetNodeById(g.preset_id);m=this.getPreset().getPresetInput(f);if(BX.type.isDomNode(m)&&BX.type.isNotEmptyString(m.value)){g.name=m.value}else{g.name=c.TITLE}}if((!("sort"in g)||!BX.type.isNumber(g.sort))&&n){E=this.getParam("PRESETS");g.sort=E.length+2}if(!s){h.forEach((function(e){if(BX.type.isArray(g.fields[e])){p=g.fields[e].length?{}:"";g.fields[e].forEach((function(e,t){p[t]=e}),this);if(p||BX.type.isNumber(p)||BX.type.isBoolean(p)){g.fields[e]=p}}}),this)}if(g.preset_id==="tmp_filter"||this.isAddPresetEnabled()||s){this.updateParams(g)}if(BX.type.isFunction(a)){a()}var v=new BX.Promise(null,this);v.setAutoResolve("fulfill",0);v.then((function(){var e=new BX.Promise(null,this);this.saveOptions(g,d,BX.proxy(e.fulfill,e));return e})).then((function(){!!r&&r()}));return v},saveFieldsSort:function e(){var t={FILTER_ID:this.getParam("FILTER_ID"),GRID_ID:this.getParam("GRID_ID"),action:"SET_FILTER"};var i=this.getPreset().getFields();var s={};s.preset_id="default_filter";if(BX.type.isArray(i)){s.rows=i.map((function(e){return BX.data(e,"name")}));s.rows=s.rows.join(",")}this.updateParams(s);this.saveOptions(s,t)},updateParams:function e(t){var i,s;if(BX.type.isPlainObject(t)&&"preset_id"in t){i=this.getPreset().getPreset(t.preset_id);if(BX.type.isPlainObject(i)){if("name"in t&&BX.type.isNotEmptyString(t.name)){i.TITLE=t.name}if("rows"in t&&!("fields"in t)){t.fields={};t.rows.split(",").forEach((function(e){t.fields[e]=""}))}if("fields"in t){i.FIELDS=this.preparePresetFields(t.fields,t.rows)}if("additional"in t&&i.ID!=="tmp_filter"){i.ADDITIONAL=this.preparePresetFields(t.additional,t.rows)}}else{s=this.getParam("PRESETS");i={ID:t.preset_id,TITLE:t.name,SORT:s.length+2,FIELDS:this.preparePresetFields(t.fields,t.rows)};s.push(i)}}},preparePresetFields:function e(t,i){var s,n;var a=[];if(BX.type.isPlainObject(t)){i=BX.type.isNotEmptyString(i)?i.split(","):[];s=i.length?i:Object.keys(t);s.forEach((function(e){e=e.replace("_datesel","").replace("_numsel","").replace("_"+BX.Filter.AdditionalFilter.Type.IS_EMPTY,"").replace("_"+BX.Filter.AdditionalFilter.Type.HAS_ANY_VALUE,"");n=BX.clone(this.getFieldByName(e));if(BX.type.isPlainObject(n)){n.ADDITIONAL_FILTER=BX.Filter.AdditionalFilter.fetchAdditionalFilter(e,t);if(!BX.Type.isStringFilled(n.ADDITIONAL_FILTER)){if(n.TYPE===this.types.STRING){n.VALUE=t[e]}if(n.TYPE===this.types.TEXTAREA){n.VALUE=t[e]}if(n.TYPE===this.types.MULTI_SELECT){n.VALUE=this.prepareMultiSelectValue(t[e],n.ITEMS)}if(n.TYPE===this.types.SELECT||n.TYPE===this.types.CHECKBOX){n.VALUE=this.prepareSelectValue(t[e],n.ITEMS)}if(n.TYPE===this.types.DATE){n.SUB_TYPE=this.prepareSelectValue(t[e+"_datesel"],n.SUB_TYPES);n.VALUES={_from:t[e+"_from"],_to:t[e+"_to"],_days:t[e+"_days"],_month:t[e+"_month"],_quarter:t[e+"_quarter"],_year:t[e+"_year"],_allow_year:t[e+"_allow_year"]}}if(n.TYPE===this.types.CUSTOM_DATE){n.VALUE={days:Object.keys(t[e+"_days"]||{}).map((function(i){return t[e+"_days"][i]})),months:Object.keys(t[e+"_months"]||{}).map((function(i){return t[e+"_months"][i]})),years:Object.keys(t[e+"_years"]||{}).map((function(i){return t[e+"_years"][i]}))}}if(n.TYPE===this.types.NUMBER){n.SUB_TYPE=this.prepareSelectValue(t[e+"_numsel"],n.SUB_TYPES);n.VALUES={_from:t[e+"_from"],_to:t[e+"_to"]}}if(n.TYPE===this.types.DEST_SELECTOR||n.TYPE===this.types.ENTITY_SELECTOR||n.TYPE===this.types.CUSTOM_ENTITY){if(typeof t[e+"_label"]!=="undefined"){n.VALUES._label=t[e+"_label"]}if(typeof t[e]!=="undefined"){n.VALUES._value=t[e]}}if(n.TYPE===this.types.CUSTOM){n._VALUE=t[e]}}a.push(n)}}),this)}return a},prepareSelectValue:function e(t,i){var s={};var n;if(BX.type.isNotEmptyString(t)&&BX.type.isArray(i)){n=this.prepareMultiSelectValue({0:t},i);s=n.length>0?n[0]:{}}else{s=i[0]}return s},prepareMultiSelectValue:function e(t,i){var s=[];if(BX.type.isPlainObject(t)&&BX.type.isArray(i)){var n=Object.keys(t);var a=n.map((function(e){return t[e]}));s=i.filter((function(e){return a.some((function(t){return t===e.VALUE}))}),this)}return s},getFieldByName:function e(t){var i=this.getParam("FIELDS");var s=i.find((function(e){return e.NAME===t}));if(s){return s}var n=this.getFieldListContainer().querySelector('[data-name="'+t+'"]');s=BX.Filter.Field.instances.get(n);if(s){return s.options}return null},confirmSaveForAll:function e(){return new Promise(function(e){var t={CONFIRM:true,CONFIRM_MESSAGE:this.getParam("MAIN_UI_FILTER__CONFIRM_MESSAGE_FOR_ALL"),CONFIRM_APPLY_BUTTON:this.getParam("MAIN_UI_FILTER__CONFIRM_APPLY_FOR_ALL"),CONFIRM_CANCEL_BUTTON:this.getParam("CONFIRM_CANCEL")};this.confirmDialog(t,e)}.bind(this))},saveOptions:function t(i,s,n,a){s.action=e(s.action);s.forAll=this.isForAll(a);s.commonPresetsId=this.getParam("COMMON_PRESETS_ID");s.apply_filter=i.apply_filter||"N";s.clear_filter=i.clear_filter||"N";s.with_preset=i.with_preset||"N";s.save=i.save||"N";s.isSetOutside=this.isSetOutside();var r={params:s,data:i};delete i.apply_filter;delete i.save;delete i.clear_filter;delete i.with_preset;if(s.forAll&&s.action==="setFilterArray"){return this.confirmSaveForAll().then(function(){return this.backend(s.action,r)}.bind(this)).then(function(){this.disableEdit();this.disableAddPreset()}.bind(this))}return this.backend(s.action,r).then(function(){BX.removeClass(this.getFindButton(),this.settings.classWaitButtonClass);BX.type.isFunction(n)&&n()}.bind(this))},backend:function e(t,i){var s=this.analyticsLabel||{};this.analyticsLabel={};return BX.ajax.runComponentAction("bitrix:main.ui.filter",t,{mode:"ajax",data:i,analyticsLabel:y({FILTER_ID:this.getParam("FILTER_ID"),GRID_ID:this.getParam("GRID_ID"),PRESET_ID:i["data"]["preset_id"],FIND:i["data"].hasOwnProperty("fields")&&i["data"]["fields"].hasOwnProperty("FIND")&&!!i["data"]["fields"]["FIND"]?"Y":"N",ROWS:BX.Type.isObject(i["data"]["additional"])&&Object.keys(i["data"]["additional"]).length==0?"N":"Y"},s)})},limitAnalyticsSend:function e(){BX.ajax.runComponentAction("bitrix:main.ui.filter","limitAnalytics",{mode:"ajax",data:{},analyticsLabel:{FILTER_ID:this.getParam("FILTER_ID"),LIMIT:this.getParam("FILTER_ID")}})},prepareEvent:function e(t){var i,s;if(!("path"in t)||!t.path.length){t.path=[t.target];i=0;while((s=t.path[i++].parentNode)!==null){t.path.push(s)}}return t},restoreRemovedPreset:function e(){if(this.getParam("VALUE_REQUIRED_MODE")){var t=this.getParam("CURRENT_PRESET");if(BX.type.isPlainObject(t)){var i=t.ID;var s=this.getPreset().getPresetNodeById(i);this.getPreset().applyPreset(i);this.getPreset().activatePreset(s)}}},hasScrollClick:function e(t){var i="clientX"in t?t.clientX:"x"in t?t.x:0;return i>=document.documentElement.offsetWidth},isUseCommonPresets:function e(){return!!this.getParam("COMMON_PRESETS_ID")},isInsideFilterEvent:function e(t){t=this.prepareEvent(t);return(t.path||[]).some((function(e){return BX.type.isDomNode(e)&&(BX.hasClass(e,this.settings.classFilterContainer)||BX.hasClass(e,this.settings.classSearchContainer)||BX.hasClass(e,this.settings.classDefaultPopup)||BX.hasClass(e,this.settings.classPopupOverlay)||BX.hasClass(e,this.settings.classSidePanelContainer))}),this)},_onDocumentClick:function e(t){var i=this.getPopup();if(!this.isInsideFilterEvent(t)&&!this.hasScrollClick(t)){if(i&&i.isShown()){this.closePopup();if(this.getParam("VALUE_REQUIRED_MODE")){this.restoreRemovedPreset()}if(this.getParam("VALUE_REQUIRED")){if(!this.getSearch().getSquares().length){this.getPreset().applyPinnedPreset()}}}BX.onCustomEvent(window,"BX.Main.Filter:blur",[this])}},_onAddFieldClick:function e(t){var i=this.getFieldsPopup();t.stopPropagation();t.preventDefault();if(i&&!i.isShown()){this.showFieldsPopup();this.syncFields()}else{this.closeFieldListPopup()}},syncFields:function e(t){if(BX.type.isPlainObject(t)){if(t.cache===false){this.fieldsPopupItems=null}}var i=this.getPreset().getFields();var s=this.getFieldsPopupItems();var n,a;if(BX.type.isArray(s)&&s.length){s.forEach((function(e){n=BX.data(e,"name").replace("_datesel","").replace("_numsel","");a=i.some((function(e){return BX.data(e,"name")===n}));if(a){BX.addClass(e,this.settings.classMenuItemChecked)}else{BX.removeClass(e,this.settings.classMenuItemChecked)}}),this)}},getFieldsPopupItems:function e(){if(!BX.type.isArray(this.fieldsPopupItems)){var t=this.getFieldsPopup();if("contentContainer"in t&&BX.type.isDomNode(t.contentContainer)){this.fieldsPopupItems=BX.Filter.Utils.getByClass(t.contentContainer,this.settings.classMenuItem,true)}this.prepareAnimation()}return this.fieldsPopupItems},getFieldListContainerClassName:function e(t){var i=parseInt(this.settings.get("popupColumnsCount",0),10);if(i>0&&i<=this.settings.maxPopupColumnCount){return this.settings.get("classPopupFieldList"+i+"Column")}var s=this.settings.classPopupFieldList1Column;if(t>6&&t<12){s=this.settings.classPopupFieldList2Column}if(t>12){s=this.settings.classPopupFieldList3Column}return s},prepareFieldsDecl:function e(t){return(t||[]).map((function(e){return{block:"main-ui-filter-field-list-item",label:"LABEL"in e?e.LABEL:"",id:"ID"in e?e.ID:"",name:"NAME"in e?e.NAME:"",item:e,sectionId:"SECTION_ID"in e?e.SECTION_ID:"",onClick:BX.delegate(this._clickOnFieldListItem,this)}}),this)},getLazyLoadFields:function e(){var t=new BX.Promise;BX.ajax({method:"GET",url:this.getParam("LAZY_LOAD")["GET_LIST"],dataType:"json",onsuccess:function e(i){t.fulfill(i)}});return t},getFieldsListPopupContent:function e(){var t=new BX.Promise;var i=this.getParam("FIELDS");var s=BX.type.isArray(i)?i.length:0;if(this.getParam("LAZY_LOAD")){var n=function(e){t.fulfill(this.getPopupContent(this.settings.classPopupFieldList,this.getFieldListContainerClassName(e.length),this.prepareFieldsDecl(e)))}.bind(this);if(BX.type.isNotEmptyObject(this.getParam("LAZY_LOAD")["CONTROLLER"])){var a=this.getParam("LAZY_LOAD")["CONTROLLER"]["componentName"];var r=this.getParam("LAZY_LOAD")["CONTROLLER"]["signedParameters"];BX.ajax.runAction(this.getParam("LAZY_LOAD")["CONTROLLER"]["getList"],{data:{filterId:this.getParam("FILTER_ID"),componentName:BX.type.isNotEmptyString(a)?a:"",signedParameters:BX.type.isNotEmptyString(r)?r:""}}).then(function(e){n(e.data)}.bind(this),(function(e){}))}else{this.getLazyLoadFields().then(n)}return t}t.fulfill(this.getPopupContent(this.settings.classPopupFieldList,this.getFieldListContainerClassName(s),this.prepareFieldsDecl(i)));return t},getPopupContent:function e(t,i,s){var n=BX.Tag.render(u||(u=babelHelpers.taggedTemplateLiteral(["<div></div>"])));if(!this.enableHeadersSections){var a=BX.decl({content:s,block:t,mix:i});this.setPopupElementWidthFromSettings(a);n.appendChild(a);if(this.enableFieldsSearch){this.preparePopupContentHeader(n)}return n}var r=this.getDefaultHeaderSection();var l={};s.forEach((function(e){var t=e.sectionId.length?e.sectionId:r.id;if(l[t]===undefined){l[t]=[]}l[t].push(e)}));this.preparePopupContentHeader(n);this.preparePopupContentFields(n,l,t,i);return n},preparePopupContentHeader:function e(t){var i=BX.Tag.render(c||(c=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="main-ui-filter-popup-search-header-wrapper">\n\t\t\t\t\t<div class="ui-form-row-inline"></div>\n\t\t\t\t</div>\n\t\t\t'])));t.prepend(i);this.preparePopupContentHeaderSections(i);this.preparePopupContentHeaderSearch(i)},preparePopupContentHeaderSections:function e(t){if(!this.enableHeadersSections){return}var i=BX.Tag.render(d||(d=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="ui-form-row">\n\t\t\t\t\t<div class="ui-form-content main-ui-filter-popup-search-section-wrapper"></div>\n\t\t\t\t</div>\n\t\t\t'])));t.firstElementChild.appendChild(i);var s=this.getHeadersSections();for(var n in s){var a=this.settings.classPopupSearchSectionItemIcon+(s[n].selected?" ".concat(this.settings.classPopupSearchSectionItemIconActive):"");var r=BX.Tag.render(h||(h=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t\t<div class="main-ui-filter-popup-search-section-item" data-ui-popup-filter-section-button="','">\n\t\t\t\t\t\t<div class="','">\n\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t\t',"\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t"])),n,a,BX.Text.encode(s[n].name));BX.bind(r,"click",this.onFilterSectionClick.bind(this,r));i.firstElementChild.appendChild(r)}},onFilterSectionClick:function e(t){var i=this.settings.classPopupSearchSectionItemIconActive;var s=t.dataset.uiPopupFilterSectionButton;var n=document.querySelectorAll("[data-ui-popup-filter-section='"+s+"']");if(BX.Dom.hasClass(t.firstElementChild,i)){BX.Dom.removeClass(t.firstElementChild,i);BX.Dom.hide(n[0])}else{BX.Dom.addClass(t.firstElementChild,i);BX.Dom.show(n[0])}},preparePopupContentHeaderSearch:function e(t){if(!this.enableFieldsSearch){return}var i=BX.Tag.render(p||(p=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="ui-form-row">\n\t\t\t\t\t<div class="ui-form-content main-ui-filter-popup-search-input-wrapper">\n\t\t\t\t\t\t<div class="ui-ctl ui-ctl-textbox ui-ctl-before-icon ui-ctl-after-icon">\n\t\t\t\t\t\t\t<div class="ui-ctl-before ui-ctl-icon-search"></div>\n\t\t\t\t\t\t\t<button class="ui-ctl-after ui-ctl-icon-clear"></button>\n\t\t\t\t\t\t\t<input type="text" class="ui-ctl-element ','">\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t'])),this.settings.classPopupSearchSectionItem);t.firstElementChild.appendChild(i);var s=i.getElementsByClassName(this.settings.classPopupSearchSectionItem);if(s.length){var n=s[0];BX.bind(n,"input",this.onFilterSectionSearchInput.bind(this,n));BX.bind(n.previousElementSibling,"click",this.onFilterSectionSearchInputClear.bind(this,n))}},preparePopupContentFields:function e(t,i,s,n){if(!this.enableHeadersSections){return}var a=BX.Tag.render(f||(f=babelHelpers.taggedTemplateLiteral(['<div class="main-ui-filter-popup-search-sections-wrapper"></div>'])));t.appendChild(a);for(var r in i){var l=BX.Tag.render(m||(m=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t\t<div class="main-ui-filter-popup-section-wrapper" data-ui-popup-filter-section="','"></div>\n\t\t\t\t'])),r);this.setPopupElementWidthFromSettings(l);if(!this.getHeadersSectionParam(r,"selected")){l.setAttribute("hidden","")}var o=BX.Tag.render(E||(E=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t\t<h3 class="main-ui-filter-popup-title">\n\t\t\t\t\t\t',"\n\t\t\t\t\t</h3>\n\t\t\t\t"])),BX.Text.encode(this.getHeadersSectionParam(r,"name")));var u=BX.decl({block:s,mix:n,content:i[r]});l.appendChild(o);l.appendChild(u);a.appendChild(l)}},prepareAnimation:function e(){var t=this;if(this.enableFieldsSearch){this.fieldsPopupItems.forEach((function(e){BX.bind(e,"animationend",t.onAnimationEnd.bind(t,e))}))}},onAnimationEnd:function e(t){t.style.display=BX.Dom.hasClass(t,this.settings.classPopupSearchFieldListItemHidden)?"none":"inline-block"},onFilterSectionSearchInput:function e(t){var i=t.value;if(i.length){i=i.toLowerCase()}this.getFieldsPopupItems().forEach(function(e){var t=e.innerText.toLowerCase();if(i.length&&t.indexOf(i)===-1){BX.Dom.removeClass(e,this.settings.classPopupSearchFieldListItemVisible);BX.Dom.addClass(e,this.settings.classPopupSearchFieldListItemHidden)}else{BX.Dom.removeClass(e,this.settings.classPopupSearchFieldListItemHidden);BX.Dom.addClass(e,this.settings.classPopupSearchFieldListItemVisible);e.style.display="inline-block"}}.bind(this))},onFilterSectionSearchInputClear:function e(t){if(t.value.length){t.value="";this.onFilterSectionSearchInput(t)}},getDefaultHeaderSection:function e(){var t=this.getHeadersSections();for(var i in t){if("selected"in t[i]&&t[i].selected){return t[i]}}return null},getHeadersSections:function e(){return this.getParam("HEADERS_SECTIONS")},getHeadersSectionParam:function e(t,i,s){if(this.getHeadersSections()[t]!==undefined&&this.getHeadersSections()[t][i]!==undefined){return this.getHeadersSections()[t][i]}return s},getFieldLoader:function e(){if(!this.fieldLoader){this.fieldLoader=new BX.Loader({mode:"custom",size:18,offset:{left:"5px",top:"5px"}})}return this.fieldLoader},_clickOnFieldListItem:function e(t){var i=t.target;var s;if(!BX.hasClass(i,this.settings.classFieldListItem)){i=BX.findParent(i,{className:this.settings.classFieldListItem},true,false)}if(BX.type.isDomNode(i)){try{s=JSON.parse(BX.data(i,"item"))}catch(e){}var n=BX.hasClass(i,this.settings.classMenuItemChecked);var a=new BX.Event.BaseEvent({data:s});this.emitter.emit(n?"onBeforeRemoveFilterItem":"onBeforeAddFilterItem",a);if(a.isDefaultPrevented()){return}var r=new BX.Promise;if(this.getParam("LAZY_LOAD")){this.getFieldLoader().show(i);var l=i.querySelector(".main-ui-select-inner-label");if(l){l.classList.add("main-ui-no-before")}var o=function(e){r.fulfill(e);this.getFieldLoader().hide();if(l){l.classList.remove("main-ui-no-before")}}.bind(this);if(BX.type.isNotEmptyObject(this.getParam("LAZY_LOAD")["CONTROLLER"])){var u=this.getParam("LAZY_LOAD")["CONTROLLER"]["componentName"];var c=this.getParam("LAZY_LOAD")["CONTROLLER"]["signedParameters"];BX.ajax.runAction(this.getParam("LAZY_LOAD")["CONTROLLER"]["getField"],{data:{filterId:this.getParam("FILTER_ID"),id:s.NAME,componentName:BX.type.isNotEmptyString(u)?u:"",signedParameters:BX.type.isNotEmptyString(c)?c:""}}).then(function(e){o(e.data)}.bind(this),(function(e){}))}else{this.getLazyLoadField(s.NAME).then(o)}}else{r.fulfill(s)}r.then(function(e){this.params.FIELDS.push(e);if(BX.hasClass(i,this.settings.classMenuItemChecked)){BX.removeClass(i,this.settings.classMenuItemChecked);this.getPreset().removeField(e)}else{if(BX.type.isPlainObject(e)){this.getPreset().addField(e);BX.addClass(i,this.settings.classMenuItemChecked);if(BX.type.isString(e.HTML)){var t=BX.create("div");this.getHiddenElement().appendChild(t);BX.html(t,e.HTML)}}}this.syncFields()}.bind(this))}},getHiddenElement:function e(){if(!this.hiddenElement){this.hiddenElement=BX.create("div");document.body.appendChild(this.hiddenElement)}return this.hiddenElement},getLazyLoadField:function e(t){var i=new BX.Promise;BX.ajax({method:"get",url:BX.util.add_url_param(this.getParam("LAZY_LOAD")["GET_FIELD"],{id:t}),dataType:"json",onsuccess:function e(t){i.fulfill(t)}});return i},showFieldsPopup:function e(){var t=this.getFieldsPopup();this.adjustFieldListPopupPosition();t.show()},closeFieldListPopup:function e(){var t=this.getFieldsPopup();t.close()},adjustFieldListPopupPosition:function e(){var t=this.getFieldsPopup();var i=BX.pos(this.getAddField());i.forceBindPosition=true;t.adjustPosition(i)},getFieldsPopup:function e(){var t=this.settings.get("showPopupInCenter",false)?null:this.getAddField();if(!this.fieldsPopup){this.fieldsPopup=new BX.PopupWindow(this.getParam("FILTER_ID")+"_fields_popup",t,{autoHide:true,offsetTop:4,offsetLeft:0,lightShadow:true,closeIcon:t===null,closeByEsc:t===null,noAllPaddings:true,zIndex:13});this.fieldsPopupLoader=new BX.Loader({target:this.fieldsPopup.contentContainer});this.fieldsPopupLoader.show();this.setPopupElementWidthFromSettings(this.fieldsPopup.contentContainer);this.fieldsPopup.contentContainer.style.height="330px";this.getFieldsListPopupContent().then(function(e){this.fieldsPopup.contentContainer.removeAttribute("style");this.fieldsPopupLoader.hide();this.fieldsPopup.setContent(e);this.syncFields({cache:false});this.adjustFieldListPopupPosition()}.bind(this))}return this.fieldsPopup},setPopupElementWidthFromSettings:function e(t){t.style.width=this.settings.popupWidth+"px"},_onAddPresetClick:function e(){this.enableAddPreset()},enableWaitSate:function e(t){!!t&&BX.addClass(t,this.settings.classWaitButtonClass)},disableWaitState:function e(t){!!t&&BX.removeClass(t,this.settings.classWaitButtonClass)},_onSaveButtonClick:function e(){var t=!!this.getSaveForAllCheckbox()&&this.getSaveForAllCheckbox().checked;var i=this.getPreset().getAddPresetFieldInput();var s=i.parentNode.querySelector(".main-ui-filter-edit-mask");var n;function a(e){if(e.animationName==="fieldError"){e.currentTarget.removeEventListener("animationend",a);e.currentTarget.removeEventListener("oAnimationEnd",a);e.currentTarget.removeEventListener("webkitAnimationEnd",a);e.currentTarget.classList.remove("main-ui-filter-error")}}function r(e){e.addEventListener("animationend",a);e.addEventListener("oAnimationEnd",a);e.addEventListener("webkitAnimationEnd",a);e.classList.add("main-ui-filter-error");var t=new BX.Promise;t.fulfill(true);return t}this.enableWaitSate(this.getFindButton());if(this.isAddPresetEnabled()&&!t){n=i.value;if(n.length){this.savePreset();this.disableAddPreset()}else{r(s).then((function(){i.focus()}))}}if(this.isEditEnabled()){var l=this.getPreset();var o=l.getPresetNodeById(l.getCurrentPresetId());var u=l.getPresetInput(o);if(u.value.length){l.updateEditablePreset(l.getCurrentPresetId());this.saveUserSettings(t);if(!t){this.disableEdit()}}else{var c=o.querySelector(".main-ui-filter-edit-mask");r(c).then((function(){u.focus()}))}}},_onCancelButtonClick:function e(){this.setIsSetOutsideState(false);this.disableAddPreset();this.getPreset().clearAddPresetFieldInput();this.disableEdit();!!this.getSaveForAllCheckbox()&&(this.getSaveForAllCheckbox().checked=null)},_onGridReady:function e(t){if(!this.grid&&t.getContainerId()===this.getParam("GRID_ID")){this.grid=t}},_onFilterMousedown:function e(t){var i=t.target;if(this.getFields().isDragButton(i)){var s=BX.Filter.Utils.getByTag(i.parentNode,"input",true);(s||[]).forEach((function(e){BX.fireEvent(e,"blur")}));BX.fireEvent(this.getFilter(),"click")}},_onFilterClick:function e(t){var i=this.getFields();var s=this.getPreset();var n;if(i.isFieldDelete(t.target)){n=i.getField(t.target);s.removeField(n)}if(i.isFieldValueDelete(t.target)){n=i.getField(t.target);i.clearFieldValue(n)}},getButtonsContainer:function e(){return BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classButtonsContainer)},getSaveButton:function e(){return BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classSaveButton)},getCancelButton:function e(){return BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classCancelButton)},getFindButton:function e(){return BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classFindButton)},getResetButton:function e(){return BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classResetButton)},getAddPresetButton:function e(){return BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classAddPresetButton)},isAddPresetEnabled:function e(){return this.isAddPresetModeState},enableAddPreset:function e(){var t=this.getPreset();var i=t.getAddPresetField();var s=t.getAddPresetFieldInput();var n=this.getButtonsContainer();BX.show(i);BX.show(n);BX.hide(this.getPresetButtonsContainer());this.hideForAllCheckbox();if(BX.type.isDomNode(s)){s.focus()}BX.addClass(this.getSidebarControlsContainer(),this.settings.classDisabled);this.isAddPresetModeState=true},disableAddPreset:function e(){var t=this.getPreset();var i=t.getAddPresetField();var s=this.getButtonsContainer();BX.hide(i);BX.hide(s);BX.show(this.getPresetButtonsContainer());this.showForAllCheckbox();t.getAddPresetFieldInput().value="";BX.removeClass(this.getSidebarControlsContainer(),this.settings.classDisabled);this.isAddPresetModeState=false},getControls:function e(){var t=this.getFieldListContainer();var i=null;if(BX.type.isDomNode(t)){i=BX.Filter.Utils.getByClass(t,this.settings.classControl,true)}return i},getFilterFields:function e(){var t=this.getFieldListContainer();var i=[];var s=[];if(BX.type.isDomNode(t)){i=BX.Filter.Utils.getByClass(t,this.settings.classField,true);s=BX.Filter.Utils.getByClass(t,this.settings.classFieldGroup,true);if(!BX.type.isArray(i)){i=[]}if(BX.type.isArray(s)){s.forEach((function(e){i.push(e)}))}}return i},getFilterFieldsValues:function e(){var t=this.getPreset().getFields();var i=this.getSearch();var s={};var n,a;s["FIND"]=i.getInput().value;if(BX.type.isArray(t)&&t.length){t.forEach((function(e){var t=BX.Filter.AdditionalFilter.getInstance().getFilter(e);if(t){Object.assign(s,t);return}n=BX.data(e,"type");a=BX.data(e,"name");switch(n){case this.types.STRING:{this.prepareControlStringValue(s,e);break}case this.types.TEXTAREA:{this.prepareControlTextareaValue(s,e);break}case this.types.NUMBER:{this.prepareControlNumberValue(s,a,e);break}case this.types.DATE:{this.prepareControlDateValue(s,a,e);break}case this.types.CUSTOM_DATE:{this.prepareControlCustomDateValue(s,a,e);break}case this.types.SELECT:{this.prepareControlSelectValue(s,a,e);break}case this.types.MULTI_SELECT:{this.prepareControlMultiselectValue(s,a,e);break}case this.types.DEST_SELECTOR:case this.types.CUSTOM_ENTITY:case this.types.ENTITY_SELECTOR:{this.prepareControlCustomEntityValue(s,a,e);break}case this.types.CUSTOM:{this.prepareControlCustomValue(s,a,e);break}default:{break}}}),this)}return s},prepareControlCustomEntityValue:function e(t,i,s){var n=this.fetchSquares(s);var a=this.fetchSquaresData(n);var r=BX.Main.ui.CustomEntity.isMultiple(s);t[i]="";t[i+"_label"]="";if(r){t[i]=[];t[i+"_label"]=[];!!a&&a.forEach((function(e){t[i].push(e._value.toString());t[i+"_label"].push(e._label.toString())}))}else{if(a.length){t[i]=a[0]._value.toString();t[i+"_label"]=a[0]._label.toString()}}},fetchSquares:function e(t){return!!t?BX.Filter.Utils.getByClass(t,this.settings.classSquare,true):[]},fetchSquaresData:function e(t){return t.map((function(e){return JSON.parse(BX.data(e,"item"))}),this)},prepareControlCustomValue:function e(t,i,s){var n=BX.Filter.Utils.getByTag(s,"input",true);t[i]="";if(BX.type.isArray(n)){n.forEach((function(e){if(BX.type.isNotEmptyString(e.name)){t[e.name]=e.value}}))}},prepareControlMultiselectValue:function e(t,i,s){var n=BX.Filter.Utils.getByClass(s,this.settings.classMultiSelect);var a=JSON.parse(BX.data(n,"value"));t[i]="";if(BX.type.isArray(a)&&a.length){t[i]={};a.forEach((function(e,s){t[i][s]=e.VALUE}))}},prepareControlSelectValue:function e(t,i,s){var n=BX.Filter.Utils.getByClass(s,this.settings.classSelect);var a=JSON.parse(BX.data(n,"value"));t[i]=a.VALUE},prepareControlCustomDateValue:function e(t,i,s){var n=s.querySelector('[data-name="'+i+"_days"+'"]');if(n){var a=JSON.parse(n.dataset.value);t[i+"_days"]=a.map((function(e){return e.VALUE}))}var r=s.querySelector('[data-name="'+i+"_months"+'"]');if(r){var l=JSON.parse(r.dataset.value);t[i+"_months"]=l.map((function(e){return e.VALUE}))}var o=s.querySelector('[data-name="'+i+"_years"+'"]');if(o){var u=JSON.parse(o.dataset.value);t[i+"_years"]=u.map((function(e){return e.VALUE}))}},prepareControlDateValue:function e(t,i,s,n){var a=s.querySelector(".main-ui-filter-additional-fields-container");if(a&&!n){BX.remove(a)}var r=BX.Filter.Utils.getByClass(s,this.settings.classSelect);var l=s.querySelector('.main-ui-select[data-name*="_allow_year"]');var o=i+this.settings.datePostfix;var u=i+this.settings.fromPostfix;var c=i+this.settings.toPostfix;var d=i+this.settings.daysPostfix;var h=i+this.settings.monthPostfix;var p=i+this.settings.quarterPostfix;var f=i+this.settings.yearPostfix;var m=i+"_allow_year";var E,g,y,v,B;t[o]="";t[u]="";t[c]="";t[d]="";t[h]="";t[p]="";t[f]="";var A=s.querySelector(".main-ui-date-input");if(A&&A.dataset.isValid==="false"){return}E=JSON.parse(BX.data(r,"value"));t[o]=E.VALUE;if(l){B=JSON.parse(BX.data(l,"value"));t[m]=B.VALUE}switch(E.VALUE){case this.dateTypes.EXACT:{g=BX.Filter.Utils.getByClass(s,this.settings.classDateInput);t[u]=g.value;t[c]=g.value;break}case this.dateTypes.QUARTER:{y=BX.Filter.Utils.getByClass(s,this.settings.classControl,true);if(BX.type.isArray(y)){y.forEach((function(e){v=BX.data(e,"name");if(v&&v.indexOf("_quarter")!==-1){t[p]=JSON.parse(BX.data(e,"value")).VALUE}if(v&&v.endsWith("_year")&&!v.endsWith("_allow_year")){t[f]=JSON.parse(BX.data(e,"value")).VALUE}}),this)}break}case this.dateTypes.YEAR:{y=BX.Filter.Utils.getByClass(s,this.settings.classControl,true);if(BX.type.isArray(y)){y.forEach((function(e){v=BX.data(e,"name");if(v&&v.endsWith("_year")&&!v.endsWith("_allow_year")){t[f]=JSON.parse(BX.data(e,"value")).VALUE}}),this)}break}case this.dateTypes.MONTH:{y=BX.Filter.Utils.getByClass(s,this.settings.classControl,true);if(BX.type.isArray(y)){y.forEach((function(e){v=BX.data(e,"name");if(v&&v.indexOf("_month")!==-1){t[h]=JSON.parse(BX.data(e,"value")).VALUE}if(v&&v.endsWith("_year")&&!v.endsWith("_allow_year")){t[f]=JSON.parse(BX.data(e,"value")).VALUE}}),this)}break}case this.additionalDateTypes.PREV_DAY:case this.additionalDateTypes.NEXT_DAY:case this.additionalDateTypes.MORE_THAN_DAYS_AGO:case this.additionalDateTypes.AFTER_DAYS:case this.dateTypes.NEXT_DAYS:case this.dateTypes.PREV_DAYS:{var P=BX.Filter.Utils.getByClass(s,this.settings.classNumberInput);if(!!P&&P.name===d){t[d]=P.value}break}case this.dateTypes.RANGE:{g=BX.Filter.Utils.getByClass(s,this.settings.classDateInput,true);g.forEach((function(e){if(e.name===u){t[u]=e.value}else if(e.name===c){t[c]=e.value}}),this);break}case"CUSTOM_DATE":{var S={};this.prepareControlCustomDateValue(S,i,s);t[i+"_days"]=S[i+"_days"];t[h]=S[i+"_months"];t[f]=S[i+"_years"];break}default:{break}}if(a&&!n){BX.append(a,s)}var _=Array.from(s.querySelectorAll('.main-ui-filter-additional-fields-container > [data-type="DATE"]'));if(_){_.forEach((function(e){var i=e.dataset.name;this.prepareControlDateValue(t,i,e,true)}),this)}},prepareControlNumberValue:function e(t,i,s){var n=BX.Filter.Utils.getByClass(s,this.settings.classNumberInput,true);var a=BX.Filter.Utils.getByClass(s,this.settings.classSelect);var r=i+this.settings.numberPostfix;var l=i+this.settings.fromPostfix;var o=i+this.settings.toPostfix;var u;t[l]="";t[o]="";u=JSON.parse(BX.data(a,"value"));t[r]=u.VALUE;n.forEach((function(e){if(e.name.indexOf(this.settings.fromPostfix)!==-1){t[l]=e.value||"";if(t[r]==="exact"){t[o]=e.value||""}}else if(e.name.indexOf(this.settings.toPostfix)!==-1){t[o]=e.value||""}}),this)},prepareControlStringValue:function e(t,i){var s=BX.Filter.Utils.getByClass(i,this.settings.classStringInput);var n;if(BX.type.isDomNode(s)){n=s.name;t[n]=s.value}},prepareControlTextareaValue:function e(t,i){var s=BX.Filter.Utils.getByClass(i,this.settings.classStringInput);var n;if(BX.type.isDomNode(s)){n=s.name;t[n]=s.value}},showGridAnimation:function e(){this.grid&&this.grid.tableFade()},hideGridAnimation:function e(){this.grid&&this.grid.tableUnfade()},getPresetId:function e(t,i){var s=this.getPreset().getCurrentPresetId();if(!this.isEditEnabled()&&!this.isAddPresetEnabled()&&!i||s==="default_filter"&&!t){s="tmp_filter"}return s},isAppliedUserFilter:function e(){var t=this;var i=this.getPreset().getCurrentPresetData();if(BX.Type.isPlainObject(i)){var s=BX.Type.isArrayFilled(i.FIELDS)&&i.FIELDS.some((function(e){return!t.getPreset().isEmptyField(e)}));var n=BX.Type.isArrayFilled(i.ADDITIONAL)&&i.ADDITIONAL.some((function(e){return!t.getPreset().isEmptyField(e)}));return!i.IS_PINNED&&(s||n)||i.IS_PINNED&&BX.Type.isArrayFilled(i.ADDITIONAL)||BX.Type.isStringFilled(this.getSearch().getSearchString())}return false},isAppliedDefaultPreset:function e(){var t=this;var i=this.getPreset().getCurrentPresetData();if(!i.IS_PINNED){return false}if(BX.Type.isArrayFilled(i.ADDITIONAL)){var s=i.ADDITIONAL.some((function(e){return!t.getPreset().isEmptyField(e)}));if(s){return false}}if(BX.Type.isStringFilled(this.getSearch().getSearchString())){return false}return true},applyFilter:function e(t,i,s){this.setIsSetOutsideState(s);var n=this.getPresetId(t,i);var a=this.getParam("FILTER_ID");var r=new BX.Promise(null,this);var l=this.getPreset();var o=this.getSearch();var u={autoResolve:!this.grid};var c=this;this.setDefaultPresetAppliedState(this.isAppliedDefaultPreset());if(this.isAppliedUserFilter()){BX.Dom.addClass(this.getSearch().container,"main-ui-filter-search--active")}else{BX.Dom.removeClass(this.getSearch().container,"main-ui-filter-search--active")}this.clearGet();this.showGridAnimation();var d=t?"clear":"apply";BX.onCustomEvent(window,"BX.Main.Filter:beforeApply",[a,{action:d},this,r]);this.updatePreset(n,null,t,null).then((function(){o.updatePreset(l.getPreset(n));if(c.getParam("VALUE_REQUIRED")){if(!o.getSquares().length){c.lastPromise=l.applyPinnedPreset()}}})).then((function(){var e={apply_filter:"Y",clear_nav:"Y"};var t=BX.delegate(r.fulfill,r);var i=BX.delegate(r.reject,r);c.grid&&c.grid.reloadTable("POST",e,t,i);BX.onCustomEvent(window,"BX.Main.Filter:apply",[a,{action:d},c,r,u]);u.autoResolve&&r.fulfill()}));return r},getAddField:function e(){return BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classAddField)},getFieldListContainer:function e(){return BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classFileldControlList)},getFields:function e(){if(!(this.fields instanceof BX.Filter.Fields)){this.fields=new BX.Filter.Fields(this)}return this.fields},getPreset:function e(){if(!(this.presets instanceof BX.Filter.Presets)){this.presets=new BX.Filter.Presets(this)}return this.presets},resetControlData:function e(t){if(BX.type.isPlainObject(t)){switch(t.TYPE){case this.types.MULTI_SELECT:{t.VALUE=[];break}case this.types.SELECT:{t.VALUE=t.ITEMS[0];break}case this.types.DATE:{t.SUB_TYPE=t.SUB_TYPES[0];t.VALUES={_from:"",_to:"",_days:"",_quarter:"",_year:""};break}case this.types.CUSTOM_DATE:{t.VALUES={days:[],months:[],years:[]};break}case this.types.NUMBER:{t.SUB_TYPE=t.SUB_TYPES[0];t.VALUES={_from:"",_to:""};break}case this.types.DEST_SELECTOR:case this.types.ENTITY_SELECTOR:case this.types.CUSTOM_ENTITY:{t.VALUES={_label:"",_value:""};break}case this.types.CUSTOM:{t._VALUE="";break}default:{t.VALUE=""}}}return t},clearControl:function e(t){var i=this.getPreset().getField({NAME:t});var s,n;if(BX.type.isDomNode(i)){s=this.getFieldByName(t);s=this.resetControlData(s);n=this.getPreset().createControl(s);BX.insertAfter(n,i);BX.remove(i)}},clearControls:function e(t){if(BX.type.isArray(t)){t.forEach((function(e){"name"in e&&this.clearControl(e.name)}),this)}else if(BX.type.isPlainObject(t)&&"name"in t){this.clearControl(t.name)}},getTemplate:function e(){return BX.html(BX(this.settings.generalTemplateId))},isIe:function e(){if(!BX.type.isBoolean(this.ie)){this.ie=BX.hasClass(document.documentElement,"bx-ie")}return this.ie},closePopup:function e(){var t=this.getPopup();var i=t.popupContainer;var s=this.settings.get("FILTER_CLOSE_DELAY");var n;BX.Dom.removeClass(this.getSearch().container,"main-ui-filter-search--showed");setTimeout(BX.delegate((function(){if(!this.isIe()){BX.removeClass(i,this.settings.classAnimationShow);BX.addClass(i,this.settings.classAnimationClose);n=parseFloat(BX.style(i,"animation-duration"));if(BX.type.isNumber(n)){n=n*1e3}setTimeout((function(){t.close()}),n)}else{t.close()}}),this),s);if(this.getParam("LIMITS_ENABLED")){BX.removeClass(this.getFilter(),this.settings.classLimitsAnimation)}this.closeFieldListPopup();this.adjustFocus()},showPopup:function e(){var t=this.getPopup();var i;if(!t.isShown()){BX.Dom.addClass(this.getSearch().container,"main-ui-filter-search--showed");this.isOpened=true;var s=this.settings.get("FILTER_SHOW_DELAY");if(this.getParam("LIMITS_ENABLED")===true){this.limitAnalyticsSend()}setTimeout(BX.delegate((function(){t.show();if(!this.isIe()){i=t.popupContainer;BX.removeClass(i,this.settings.classAnimationClose);BX.addClass(i,this.settings.classAnimationShow);BX.onCustomEvent(window,"BX.Main.Filter:show",[this])}var e=[].slice.call(this.getFieldListContainer().querySelectorAll("textarea"));e.forEach((function(e){BX.style(e,"height",e.scrollHeight+"px")}))}),this),s)}},getSaveForAllCheckbox:function e(){if(!this.saveForAllCheckbox&&!!this.getSaveForAllCheckboxContainer()){this.saveForAllCheckbox=BX.Filter.Utils.getBySelector(this.getSaveForAllCheckboxContainer(),'input[type="checkbox"]')}return this.saveForAllCheckbox},getSaveForAllCheckboxContainer:function e(){if(!this.saveForAllCheckboxContainer){this.saveForAllCheckboxContainer=BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classForAllCheckbox)}return this.saveForAllCheckboxContainer},showForAllCheckbox:function e(){!!this.getSaveForAllCheckboxContainer()&&BX.removeClass(this.getSaveForAllCheckboxContainer(),this.settings.classHide)},hideForAllCheckbox:function e(){!!this.getSaveForAllCheckboxContainer()&&BX.addClass(this.getSaveForAllCheckboxContainer(),this.settings.classHide)},getPopupBindElement:function e(){if(!this.popupBindElement){var t=this.settings.get("POPUP_BIND_ELEMENT_SELECTOR");var i=null;if(BX.type.isNotEmptyString(t)){i=BX.Filter.Utils.getBySelector(document,t)}this.popupBindElement=!!i?i:this.getSearch().getContainer()}return this.popupBindElement},getPopup:function e(){if(!(this.popup instanceof BX.PopupWindow)){this.popup=new BX.PopupWindow(this.getParam("FILTER_ID")+this.settings.searchContainerPostfix,this.getPopupBindElement(),{autoHide:false,offsetTop:parseInt(this.settings.get("POPUP_OFFSET_TOP")),offsetLeft:parseInt(this.settings.get("POPUP_OFFSET_LEFT")),lightShadow:true,closeIcon:false,closeByEsc:false,noAllPaddings:true,zIndex:12});this.popup.setContent(this.getTemplate());BX.bind(this.getFieldListContainer(),"keydown",BX.delegate(this._onFieldsContainerKeydown,this));BX.bind(this.getFilter(),"click",BX.delegate(this._onFilterClick,this));BX.bind(this.getAddPresetButton(),"click",BX.delegate(this._onAddPresetClick,this));BX.bind(this.getPreset().getAddPresetFieldInput(),"keydown",BX.delegate(this._onAddPresetKeydown,this));BX.bind(this.getPreset().getContainer(),"keydown",BX.delegate(this._onPresetInputKeydown,this));BX.bind(this.getSaveButton(),"click",BX.delegate(this._onSaveButtonClick,this));BX.bind(this.getCancelButton(),"click",BX.delegate(this._onCancelButtonClick,this));BX.bind(this.getFindButton(),"click",BX.delegate(this._onFindButtonClick,this));BX.bind(this.getResetButton(),"click",BX.delegate(this._onResetButtonClick,this));BX.bind(this.getAddField(),"click",BX.delegate(this._onAddFieldClick,this));BX.bind(this.getEditButton(),"click",BX.delegate(this._onEditButtonClick,this));BX.bind(this.getRestoreButton(),"click",BX.delegate(this._onRestoreButtonClick,this));BX.bind(this.getRestoreFieldsButton(),"click",BX.delegate(this._onRestoreFieldsButtonClick,this));this.getFilter().addEventListener("mousedown",BX.delegate(this._onFilterMousedown,this),true);this.getPreset().showCurrentPresetFields();this.getPreset().bindOnPresetClick()}return this.popup},_onRestoreFieldsButtonClick:function e(){this.restoreDefaultFields()},restoreDefaultFields:function e(){var t=this.getPreset().getPreset("default_filter",true);var i=this.getParam("PRESETS");var s=this.getPreset().getCurrentPresetId();var n={FILTER_ID:this.getParam("FILTER_ID"),GRID_ID:this.getParam("GRID_ID"),action:"SET_FILTER"};var a=t.FIELDS.map((function(e){return e.NAME}));var r=a.join(",");i.forEach((function(e,s){if(e.ID==="default_filter"){i[s]=BX.clone(t)}}),this);if(BX.type.isArray(this.editablePresets)){this.editablePresets.forEach((function(e,i){if(e.ID==="default_filter"){this.editablePresets[i]=BX.clone(t)}}),this)}this.getPreset().applyPreset(s);this.updatePreset(s);this.saveOptions({preset_id:"default_filter",rows:r,save:"Y",apply_filter:"N"},n)},getRestoreFieldsButton:function e(){if(!this.restoreFieldsButton){this.restoreFieldsButton=BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classRestoreFieldsButton)}return this.restoreFieldsButton},restoreFilter:function e(){var t=this.getParam("DEFAULT_PRESETS");var i=this.getParam("PRESETS");var s=false;var n,a,r;if(BX.type.isArray(t)){t.sort((function(e,t){return e.SORT-t.SORT}));t.forEach((function(e){s=i.some((function(t,i){if(t.ID===e.ID){n=i;return true}}));if(s){i[n]=BX.clone(e)}else{i.push(BX.clone(e))}if(e.ID!=="default_filter"){this.addSidebarItem(e.ID,e.TITLE,e.IS_PINNED);if(e.IS_PINNED){a=e.ID}}}),this)}this.saveRestoreFilter();this.disableAddPreset();this.disableEdit();if(!a){a="default_filter"}r=this.getPreset().getPresetNodeById(a);if(r){BX.fireEvent(r,"click")}},saveRestoreFilter:function e(){var t={FILTER_ID:this.getParam("FILTER_ID"),GRID_ID:this.getParam("GRID_ID"),action:"RESTORE_FILTER"};var i=this.getParam("PRESETS");var s={};var n;if(BX.type.isArray(i)){i.forEach((function(e){n=e.FIELDS.map((function(e){return e.NAME}));n=n.join(",");s[e.ID]={name:e.TITLE||null,sort:e.SORT,preset_id:e.ID,fields:this.prepareFields(e.FIELDS),rows:n,for_all:e.FOR_ALL}}),this);this.saveOptions(s,t)}},prepareFields:function e(t){var i={};var s;if(BX.type.isArray(t)){t.forEach((function(e){if(e.TYPE===this.types.SELECT){i[e.NAME]="VALUE"in e.VALUE?e.VALUE.VALUE:""}if(e.TYPE===this.types.MULTI_SELECT){e.VALUE.forEach((function(t,s){i[e.NAME]=i[e.NAME]||{};i[e.NAME][s]=t.VALUE}));i[e.NAME]=i[e.NAME]||""}if(e.TYPE===this.types.DATE||e.TYPE===this.types.NUMBER){s=Object.keys(e.VALUES);s.forEach((function(t){i[e.NAME+t]=e.VALUES[t]}));if(e.TYPE===this.types.DATE){i[e.NAME+"_datesel"]="VALUE"in e.SUB_TYPE?e.SUB_TYPE.VALUE:e.SUB_TYPES[0].VALUE}if(e.TYPE===this.types.NUMBER){i[e.NAME+"_numsel"]="VALUE"in e.SUB_TYPE?e.SUB_TYPE.VALUE:e.SUB_TYPES[0].VALUE}}if(e.TYPE===this.types.DEST_SELECTOR||e.TYPE===this.types.ENTITY_SELECTOR||e.TYPE===this.types.CUSTOM_ENTITY){i[e.NAME+"_label"]=e.VALUES._label;i[e.NAME+"_value"]=e.VALUES._value}}),this)}return i},getRestoreButton:function e(){if(!BX.type.isDomNode(this.restoreButton)){this.restoreButton=BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classRestoreButton)}return this.restoreButton},_onPresetInputKeydown:function e(t){if(BX.Filter.Utils.isKey(t,"enter")&&t.target.tagName==="INPUT"){BX.fireEvent(this.getSaveButton(),"click")}},_onFieldsContainerKeydown:function e(t){if(BX.Filter.Utils.isKey(t,"enter")&&t.target.tagName==="INPUT"){BX.fireEvent(this.getFindButton(),"click")}},_onFindButtonClick:function e(){this.setIsSetOutsideState(false);var t=this.getPreset();var i=t.getCurrentPresetId();var s;if(i!=="tmp_filter"&&i!=="default_filter"&&!t.isPresetValuesModified(i)){var n=t.getPreset(i);var a=t.getAdditionalValues(i);var r=t.getFields().map((function(e){return BX.data(e,"name")}));n.ADDITIONAL=this.preparePresetFields(a,r);n.ADDITIONAL=n.ADDITIONAL.filter((function(e){return!this.getPreset().isEmptyField(e)}),this);s=this.applyFilter(false,i);this.closePopup()}else{t.deactivateAllPresets();s=this.applyFilter();this.closePopup()}return s},_onResetButtonClick:function e(){if(this.getParam("VALUE_REQUIRED")){var t=this.getPreset().getCurrentPresetData();if(t.ADDITIONAL.length){this.closePopup()}BX.fireEvent(this.getSearch().getClearButton(),"click")}else{if(this.getParam("RESET_TO_DEFAULT_MODE")){this.getSearch().clearInput();this.getPreset().applyPinnedPreset()}else{this.resetFilter()}this.closePopup()}},resetFilter:function e(t){var i=this.getSearch();var s=this.getPreset();if(!t){i.clearInput()}i.removePreset();s.deactivateAllPresets();s.resetPreset(true);i.hideClearButton();i.adjustPlaceholder();return this.applyFilter(true,true)},_onEditButtonClick:function e(){if(!this.isEditEnabled()){this.enableEdit()}else{this.disableEdit()}},enableFieldsDragAndDrop:function e(){var t=this.getPreset().getFields();this.fieldsList=[];if(BX.type.isArray(t)){this.fieldsList=t.map(this.registerDragItem,this)}},registerDragItem:function e(t){var i=this.getDragButton(t);if(i){i.onbxdragstart=BX.delegate(this._onFieldDragStart,this);i.onbxdragstop=BX.delegate(this._onFieldDragStop,this);i.onbxdrag=BX.delegate(this._onFieldDrag,this);jsDD.registerObject(i);jsDD.registerDest(i)}return t},unregisterDragItem:function e(t){var i=this.getDragButton(t);if(i){jsDD.unregisterObject(i);jsDD.unregisterDest(i)}},_onFieldDragStart:function e(){this.dragItem=this.getFields().getField(jsDD.current_node);this.dragIndex=BX.Filter.Utils.getIndex(this.fieldsList,this.dragItem);this.dragRect=this.dragItem.getBoundingClientRect();this.offset=this.dragRect.height;this.dragStartOffset=jsDD.start_y-(this.dragRect.top+BX.scrollTop(window));BX.Filter.Utils.styleForEach(this.fieldsList,{transition:"100ms"});BX.addClass(this.dragItem,this.settings.classPresetOndrag);BX.bind(document,"mousemove",BX.delegate(this._onMouseMove,this))},_onFieldDragStop:function e(){BX.unbind(document,"mousemove",BX.delegate(this._onMouseMove,this));BX.removeClass(this.dragItem,this.settings.classPresetOndrag);BX.Filter.Utils.styleForEach(this.fieldsList,{transition:"",transform:""});BX.Filter.Utils.collectionSort(this.dragItem,this.targetItem);this.fieldsList=this.getPreset().getFields();this.saveFieldsSort()},_onFieldDrag:function e(){var t=this;var i,s;this.dragOffset=this.realY-this.dragRect.top-this.dragStartOffset;this.sortOffset=t.realY+BX.scrollTop(window);BX.Filter.Utils.styleForEach([this.dragItem],{transition:"0ms",transform:"translate3d(0px, "+this.dragOffset+"px, 0px)"});this.fieldsList.forEach((function(e,n){if(e){i=e.getBoundingClientRect();s=i.top+BX.scrollTop(window)+i.height/2;if(n>t.dragIndex&&t.sortOffset>s&&e.style.transform!=="translate3d(0px, "+-t.offset+"px, 0px)"&&e.style.transform!==""){t.targetItem=e;BX.style(e,"transform","translate3d(0px, "+-t.offset+"px, 0px)");BX.style(e,"transition","300ms")}if(n<t.dragIndex&&t.sortOffset<s&&e.style.transform!=="translate3d(0px, "+t.offset+"px, 0px)"&&e.style.transform!==""){t.targetItem=e;BX.style(e,"transform","translate3d(0px, "+t.offset+"px, 0px)");BX.style(e,"transition","300ms")}if((n<t.dragIndex&&t.sortOffset>s||n>t.dragIndex&&t.sortOffset<s)&&e.style.transform!=="translate3d(0px, 0px, 0px)"){if(e.style.transform!==""){t.targetItem=e}BX.style(e,"transform","translate3d(0px, 0px, 0px)");BX.style(e,"transition","300ms")}}}))},disableFieldsDragAndDrop:function e(){if(BX.type.isArray(this.fieldsList)&&this.fieldsList.length){this.fieldsList.map(this.unregisterDragItem,this)}},enablePresetsDragAndDrop:function e(){var t,i,s,n;t=this.getPreset();i=t.getPresets();this.presetsList=[];if(BX.type.isArray(i)&&i.length){i.forEach((function(e){n=t.getPresetId(e);if(!BX.hasClass(e,this.settings.classAddPresetField)&&n!=="default_filter"&&!BX.hasClass(e,this.settings.classDefaultFilter)){s=this.getDragButton(e);s.onbxdragstart=BX.delegate(this._onDragStart,this);s.onbxdragstop=BX.delegate(this._onDragStop,this);s.onbxdrag=BX.delegate(this._onDrag,this);jsDD.registerObject(s);jsDD.registerDest(s);this.presetsList.push(e)}}),this)}},getDragButton:function e(t){return BX.Filter.Utils.getByClass(t,this.settings.classPresetDragButton)},disablePresetsDragAndDrop:function e(){if(BX.type.isArray(this.presetsList)&&this.presetsList.length){this.presetsList.forEach((function(e){if(!BX.hasClass(e,this.settings.classAddPresetField)){jsDD.unregisterObject(e);jsDD.unregisterDest(e)}}),this)}},_onDragStart:function e(){this.dragItem=this.getPreset().normalizePreset(jsDD.current_node);this.dragIndex=BX.Filter.Utils.getIndex(this.presetsList,this.dragItem);this.dragRect=this.dragItem.getBoundingClientRect();this.offset=this.dragRect.height;this.dragStartOffset=jsDD.start_y-(this.dragRect.top+BX.scrollTop(window));BX.Filter.Utils.styleForEach(this.list,{transition:"100ms"});BX.addClass(this.dragItem,this.settings.classPresetOndrag);BX.bind(document,"mousemove",BX.delegate(this._onMouseMove,this))},_onMouseMove:function e(t){this.realX=t.clientX;this.realY=t.clientY},getDragOffset:function e(){return jsDD.x-this.startDragOffset-this.dragRect.left},_onDragStop:function e(){var t,i;BX.unbind(document,"mousemove",BX.delegate(this._onMouseMove,this));BX.removeClass(this.dragItem,this.settings.classPresetOndrag);BX.Filter.Utils.styleForEach(this.presetsList,{transition:"",transform:""});BX.Filter.Utils.collectionSort(this.dragItem,this.targetItem);t=this.getPreset();i=t.getPresets();this.presetsList=[];if(BX.type.isArray(i)&&i.length){i.forEach((function(e){if(!BX.hasClass(e,this.settings.classAddPresetField)&&!BX.hasClass(e,this.settings.classDefaultFilter)){this.presetsList.push(e)}}),this)}},_onDrag:function e(){var t=this;var i,s;this.dragOffset=this.realY-this.dragRect.top-this.dragStartOffset;this.sortOffset=t.realY+BX.scrollTop(window);BX.Filter.Utils.styleForEach([this.dragItem],{transition:"0ms",transform:"translate3d(0px, "+this.dragOffset+"px, 0px)"});this.presetsList.forEach((function(e,n){if(e){i=e.getBoundingClientRect();s=i.top+BX.scrollTop(window)+i.height/2;if(n>t.dragIndex&&t.sortOffset>s&&e.style.transform!=="translate3d(0px, "+-t.offset+"px, 0px)"&&e.style.transform!==""){t.targetItem=e;BX.style(e,"transform","translate3d(0px, "+-t.offset+"px, 0px)");BX.style(e,"transition","300ms")}if(n<t.dragIndex&&t.sortOffset<s&&e.style.transform!=="translate3d(0px, "+t.offset+"px, 0px)"&&e.style.transform!==""){t.targetItem=e;BX.style(e,"transform","translate3d(0px, "+t.offset+"px, 0px)");BX.style(e,"transition","300ms")}if((n<t.dragIndex&&t.sortOffset>s||n>t.dragIndex&&t.sortOffset<s)&&e.style.transform!=="translate3d(0px, 0px, 0px)"){if(e.style.transform!==""){t.targetItem=e}BX.style(e,"transform","translate3d(0px, 0px, 0px)");BX.style(e,"transition","300ms")}}}))},getSidebarControlsContainer:function e(){if(!BX.type.isDomNode(this.sidebarControlsContainer)){this.sidebarControlsContainer=BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classSidebarControlsContainer)}return this.sidebarControlsContainer},enableEdit:function e(){var t=this.getPreset();var i=t.getPresets();var s;if(BX.type.isArray(i)&&i.length){i.forEach((function(e){s=t.getPresetId(e);if(!BX.hasClass(e,this.settings.classAddPresetField)&&s!=="default_filter"){BX.addClass(e,this.settings.classPresetEdit)}}),this)}this.enablePresetsDragAndDrop();BX.show(this.getButtonsContainer());BX.hide(this.getPresetButtonsContainer());BX.addClass(this.getSidebarControlsContainer(),this.settings.classDisabled);this.editablePresets=BX.clone(this.getParam("PRESETS"));this.isEditEnabledState=true},disableEdit:function e(){var t=this.getPreset();var i=t.getPresets();if(BX.type.isArray(i)&&i.length){i.forEach((function(e){if(!BX.hasClass(e,this.settings.classAddPresetField)){BX.removeClass(e,this.settings.classPresetEdit);this.getPreset().disableEditPresetName(e)}}),this)}this.disablePresetsDragAndDrop();if(!this.isAddPresetEnabled()){BX.style(this.getButtonsContainer(),"display","")}BX.show(this.getPresetButtonsContainer());BX.removeClass(this.getSidebarControlsContainer(),this.settings.classDisabled);this.editablePresets=null;this.isEditEnabledState=false;this.applyFilter(null,true)},getPresetButtonsContainer:function e(){if(!BX.type.isDomNode(this.presetButtonsContainer)){this.presetButtonsContainer=BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classPresetButtonsContainer)}return this.presetButtonsContainer},isEditEnabled:function e(){return this.isEditEnabledState},getEditButton:function e(){return BX.Filter.Utils.getByClass(this.getFilter(),this.settings.classEditButton)},getParam:function e(t,i){return t in this.params?this.params[t]:i},getFilter:function e(){return BX.Filter.Utils.getByClass(this.getPopup().contentContainer,this.settings.classFilterContainer)},getSearch:function e(){if(!(this.search instanceof BX.Filter.Search)){this.search=new BX.Filter.Search(this)}return this.search},_onRestoreButtonClick:function e(){var t={CONFIRM:true,CONFIRM_MESSAGE:this.getParam("CONFIRM_MESSAGE"),CONFIRM_APPLY_BUTTON:this.getParam("CONFIRM_APPLY"),CONFIRM_CANCEL_BUTTON:this.getParam("CONFIRM_CANCEL")};this.confirmDialog(t,BX.delegate(this.restoreFilter,this))},confirmDialog:function e(t,i,s){if("CONFIRM"in t&&t.CONFIRM){var n=this.getParam("FILTER_ID")+"-confirm-dialog";var a='<div class="main-ui-filter-confirm-content">'+t.CONFIRM_MESSAGE+"</div>";var r="CONFIRM_TITLE"in t?t.CONFIRM_TITLE:"";var l=new BX.PopupWindowButton({text:t.CONFIRM_APPLY_BUTTON,events:{click:function e(){BX.type.isFunction(i)?i():null;this.popupWindow.close();this.popupWindow.destroy()}}});var o=new BX.PopupWindowButtonLink({text:t.CONFIRM_CANCEL_BUTTON,events:{click:function e(){BX.type.isFunction(s)?s():null;this.popupWindow.close();this.popupWindow.destroy()}}});var u=new BX.PopupWindow(n,null,{content:a,titleBar:r,autoHide:false,zIndex:9999,overlay:.4,offsetTop:-100,closeIcon:true,closeByEsc:true,buttons:[l,o]});BX.addCustomEvent(u,"onPopupClose",BX.delegate((function(){!!this.getSaveForAllCheckbox()&&(this.getSaveForAllCheckbox().checked=null)}),this));if(!u.isShown()){u.show();var c=u.popupContainer;BX.removeClass(c,this.settings.classAnimationShow);BX.addClass(c,this.settings.classAnimationShow)}}else{BX.type.isFunction(i)?i():null}},getInitialValue:function e(t){if(BX.type.isString(t)){var i=this.params.INITIAL_FILTER;if(BX.type.isPlainObject(i)){var s=Object.entries(i).reduce((function(e,i){if(i[0].startsWith(t)){e.push(i)}return e}),[]);if(s.length===1){return s[0][1]}if(s.length>1){return s.reduce((function(e,i){e[i[0].replace(t,"")]=i[1];return e}),{})}}}return""},getField:function e(t){var i=this.getFieldListContainer().querySelector('[data-name="'+t+'"]');return BX.Filter.Field.instances.get(i)},isSetOutside:function e(){return BX.Text.toBoolean(this.isSetOutsideState)},setIsSetOutsideState:function e(t){this.isSetOutsideState=BX.Text.toBoolean(t);var i=this.getSearch().getContainer();if(this.isSetOutsideState){BX.Dom.addClass(i,"main-ui-filter-set-outside");BX.Dom.removeClass(i,"main-ui-filter-set-inside")}else{BX.Dom.addClass(i,"main-ui-filter-set-inside");BX.Dom.removeClass(i,"main-ui-filter-set-outside")}},setDefaultPresetAppliedState:function e(t){this.isDefaultPresetAppliedState=BX.Text.toBoolean(t);var i=this.getSearch().getContainer();if(this.isDefaultPresetAppliedState){BX.Dom.addClass(i,"main-ui-filter-default-applied")}else{BX.Dom.removeClass(i,"main-ui-filter-default-applied")}}}})();(function(){BX.Main.filterManager={data:{},push:function e(t,i){if(BX.type.isNotEmptyString(t)&&i){this.data[t]=i}},getById:function e(t){var i=null;if(t in this.data){i=this.data[t]}return i},getList:function e(){return Object.values(this.data)}}})();var v;function B(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,s)}return i}function A(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?B(Object(i),!0).forEach((function(t){babelHelpers.defineProperty(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):B(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}var P=Symbol("onValueChange");var S=function(e){babelHelpers.inherits(t,e);function t(e){var i;babelHelpers.classCallCheck(this,t);i=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,e));i.setEventNamespace("BX.Filter.Field");i.id=e.options.NAME;i.parent=e.parent;i.node=e.node;i.options=A({},e.options);i.cache=new n.Cache.MemoryCache;i[P]=i[P].bind(babelHelpers.assertThisInitialized(i));n.Event.bind(i.node,"input",i[P]);n.Event.bind(i.node,"change",i[P]);var s=babelHelpers.toConsumableArray(i.node.querySelectorAll(".main-ui-control-value-delete"));s.forEach((function(e){e.addEventListener("click",(function(){setTimeout((function(){i[P]()}))}))}));var a=new MutationObserver((function(){i[P]()}));var r=babelHelpers.toConsumableArray(i.node.querySelectorAll(".main-ui-select"));r.forEach((function(e){a.observe(e,{attributes:true,attributeFilter:["data-value"]})}));t.instances.set(i.node,babelHelpers.assertThisInitialized(i));return i}babelHelpers.createClass(t,[{key:"subscribe",value:function e(t,i){n.Event.EventEmitter.subscribe(this,t.replace("BX.Filter.Field:",""),i)}},{key:P,value:function e(){this.emit("change",{field:this,value:this.getValue()})}},{key:"getAdditionalFieldContainer",value:function e(){return this.cache.remember("additionalFieldsContainer",(function(){return n.Tag.render(v||(v=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="main-ui-filter-additional-fields-container"></div>\n\t\t\t'])))}))}},{key:"hasAdditional",value:function e(){return n.Dom.hasClass(this.node,"main-ui-filter-field-with-additional-fields")}},{key:"addAdditionalField",value:function e(i){if(!this.hasAdditional()){n.Dom.addClass(this.node,"main-ui-filter-field-with-additional-fields");n.Dom.append(this.getAdditionalFieldContainer(),this.node)}var s=this.parent.getPreset();var a=this.prepareFieldOptions(i);var r=s.createControl(a);this.appendRenderedField(r);return t.instances.get(r)}},{key:"prepareListItems",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};if(n.Type.isPlainObject(t)){return Object.entries(t).map((function(e){var t=babelHelpers.slicedToArray(e,2),i=t[0],s=t[1];return{NAME:s,VALUE:i}}))}return{}}},{key:"prepareFieldOptions",value:function e(t){var i=this;if(n.Type.isPlainObject(t)){var s=this.parent.params.FIELDS_STUBS;var a=t.type,r=a===void 0?"string":a;var l=s.find((function(e){return e.NAME===r}));if(n.Type.isPlainObject(l)){var o=A(A({},l),{},{NAME:t.id,LABEL:t.name,TYPE:r==="checkbox"?"SELECT":l.TYPE,VALUE_REQUIRED:t.valueRequired===true});if(r==="list"){return A(A({},o),{},{ITEMS:[].concat(babelHelpers.toConsumableArray(o.ITEMS),[this.prepareListItems(t.items)]),params:{isMulti:function(){if(n.Type.isPlainObject(t.params)){return t.params===true}return false}()}})}if(r==="date"){var u=function(){if(n.Type.isPlainObject(t.value)&&Reflect.has(t.value,"_datesel")){return t.value._datesel}return i.parent.dateTypes.NONE}();return A(A({},o),{},{SUB_TYPES:function(){if(n.Type.isArray(t.exclude)){return o.SUB_TYPES.filter((function(e){return!t.exclude.includes(e.VALUE)}))}return o.SUB_TYPES}(),SUB_TYPE:function(){return o.SUB_TYPES.find((function(e){return e.VALUE===u}))}(),VALUES:function(){if(n.Type.isPlainObject(t.value)){return A({},t.value)}return o.VALUES}()})}if(r==="string"||r==="custom_date"||r==="number"||r==="checkbox"||r==="custom_entity"){return o}}}return t}},{key:"appendRenderedField",value:function e(t){if(n.Type.isDomNode(t)){var i=this.getAdditionalFieldContainer();n.Dom.append(t,i)}}},{key:"getValue",value:function e(){var t=this.parent.getFilterFieldsValues();var i=this.options,s=i.TYPE,n=i.NAME;if(s==="DATE"||s==="NUMBER"){return Object.entries(t).reduce((function(e,t){var i=babelHelpers.slicedToArray(t,2),s=i[0],a=i[1];if(s.startsWith(n)){e[s.replace(n,"")]=a}return e}),{})}if(n in t){return t[n]}return""}},{key:"setValue",value:function e(t){var i=this;var s=this.options.TYPE;if(s==="DATE"||s==="NUMBER"){if(n.Type.isPlainObject(t)){var a=this.parent.getFieldListContainer();Object.entries(t).forEach((function(e){var t=babelHelpers.slicedToArray(e,2),s=t[0],r=t[1];var l=a.querySelector('[data-name="'.concat(i.id,'"] [data-name="').concat(i.id).concat(s,'"], [data-name="').concat(i.id,'"] [name="').concat(i.id).concat(s,'"]'));if(l){if(n.Dom.hasClass(l,"main-ui-select")){var o=n.Dom.attr(l,"data-items");if(n.Type.isArray(o)){var u=o.find((function(e){return e.VALUE===r}));if(n.Type.isPlainObject(u)){n.Dom.attr(l,"data-value",u);var c=l.querySelector(".main-ui-select-name");if(c){c.innerText=u.NAME}var d=BX.Main.ui.Factory.get(l);if(!d){d={node:l,instance:new BX.Main.ui.select(l)};BX.Main.ui.Factory.data.push(d)}if(n.Type.isPlainObject(d)){BX.onCustomEvent(window,"UI::Select::Change",[d.instance,u])}}}}else if(l.tagName==="INPUT"){l.value=r}}}))}}}}]);return t}(n.Event.EventEmitter);babelHelpers.defineProperty(S,"instances",new WeakMap);var _=function(){function e(t){babelHelpers.classCallCheck(this,e);this.parent=t}babelHelpers.createClass(e,[{key:"setFields",value:function e(t){if(n.Type.isPlainObject(t)){this.parent.getPopup();var i=this.parent.getPreset();i.deactivateAllPresets();var s={preset_id:"tmp_filter",fields:t};this.parent.updateParams(s);i.applyPreset("tmp_filter")}}},{key:"setFilter",value:function e(t){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;this.setAnalyticsLabel(i);if(n.Type.isObject(t)){this.parent.updateParams(t);this.parent.getPreset().deactivateAllPresets();this.parent.getPreset().activatePreset(t.preset_id);this.parent.getPreset().applyPreset(t.preset_id);if(!t.checkFields||!this.parent.getPreset().isPresetValuesModified(t.preset_id)){var s=true;this.parent.applyFilter(false,t.preset_id,s)}else{var a={};if(n.Type.isPlainObject(t.fields)){a=Object.assign({},t.fields)}if(n.Type.isPlainObject(t.additional)){a=Object.assign({},t.additional)}this.parent.getPreset().deactivateAllPresets();this.setFields(a);this.apply()}}}},{key:"extendFilter",value:function e(t){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;this.setAnalyticsLabel(s);if(n.Type.isObject(t)){Object.keys(t).forEach((function(e){if(n.Type.isNumber(t[e])){t[e]=String(t[e])}}));var a=this.parent.getPreset().getCurrentPresetId();if(i||a==="tmp_filter"||a==="default_filter"){var r=Object.assign({},this.parent.getFilterFieldsValues(),t);this.setFields(r);this.apply();return}var l=this.parent.getPreset().getAdditionalValues(a);if(n.Type.isPlainObject(l)&&Object.keys(l).length){t=Object.assign({},l,t)}this.setFilter({preset_id:a,additional:t,checkFields:true})}}},{key:"apply",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;this.setAnalyticsLabel(t);if(!this.parent.isEditEnabled()){if(!this.parent.isEditEnabled()){var i=false;var s=false;var n=true;this.parent.applyFilter(i,s,n)}this.parent.closePopup();if(this.parent.isAddPresetEnabled()){this.parent.disableAddPreset()}}}},{key:"getEmitter",value:function e(){return this.parent.emitter}},{key:"setAnalyticsLabel",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;if(n.Type.isObject(t)){this.parent.analyticsLabel=t}}}]);return e}();function L(e){return{block:"main-ui-control-field",type:e.type,dragButton:false,content:{block:"main-ui-date",mix:["filter-type-single"],calendarButton:true,valueDelete:true,placeholder:e.placeholder,name:e.name,tabindex:e.tabindex,value:e.value,enableTime:e.enableTime}}}function b(e){return{block:"main-ui-control-field",type:e.type,dragButton:false,content:{block:"main-ui-number",mix:["filter-type-single"],valueDelete:true,placeholder:e.placeholder,name:e.name,tabindex:e.tabindex,value:e.value}}}function I(){return{block:"main-ui-filter-field-line",content:{block:"main-ui-filter-field-line-item",tag:"span"}}}function T(e){return{block:"main-ui-control-field",dragButton:false,content:{block:"main-ui-select",tabindex:e.tabindex,value:e.value,items:e.items,name:e.name,valueDelete:false}}}var F,D;function X(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,s)}return i}function C(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?X(Object(i),!0).forEach((function(t){babelHelpers.defineProperty(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):X(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}var N=function(e){babelHelpers.inherits(t,e);babelHelpers.createClass(t,null,[{key:"getInstance",value:function e(){return t.cache.remember("instance",(function(){return new t}))}},{key:"fetchAdditionalFilter",value:function e(i,s){if(n.Type.isStringFilled(i)&&n.Type.isPlainObject(s)){if("".concat(i,"_").concat(t.Type.IS_EMPTY)in s){return t.Type.IS_EMPTY}if("".concat(i,"_").concat(t.Type.HAS_ANY_VALUE)in s){return t.Type.HAS_ANY_VALUE}}return null}}]);function t(){var e;var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};babelHelpers.classCallCheck(this,t);e=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this));babelHelpers.defineProperty(babelHelpers.assertThisInitialized(e),"cache",new n.Cache.MemoryCache);e.setEventNamespace("BX.Main.Filter.AdditionalFilter");e.options=C({},i);n.Event.bind(document,"click",e.onDocumentClick.bind(babelHelpers.assertThisInitialized(e)));return e}babelHelpers.createClass(t,[{key:"getAdditionalFilterMenu",value:function e(){var i=this;return this.cache.remember("menu",(function(){return new s.Menu({id:"additional_filter_menu",autoHide:false,items:[{id:"isEmpty",text:n.Loc.getMessage("MAIN_UI_FILTER__ADDITIONAL_FILTER_MENU_IS_EMPTY"),onclick:i.onAdditionalFilterMenuItemClick.bind(i,t.Type.IS_EMPTY)},{id:"hasAnyValue",text:n.Loc.getMessage("MAIN_UI_FILTER__ADDITIONAL_FILTER_MENU_HAS_ANY_VALUE"),onclick:i.onAdditionalFilterMenuItemClick.bind(i,t.Type.HAS_ANY_VALUE)},{id:"delimiter",delimiter:true},{id:"helper",html:n.Loc.getMessage("MAIN_UI_FILTER__ADDITIONAL_FILTER_PLACEHOLDER_HOW")+'<span class="ui-hint"><span class="ui-hint-icon"></span></span>',onclick:function e(){if(top.BX.Helper){top.BX.Helper.show("redirect=detail&code=14006190");event.preventDefault()}}}]})}))}},{key:"onAdditionalFilterMenuItemClick",value:function e(t){var i=this.getCurrentFieldNode();this.initAdditionalFilter(i,t)}},{key:"onDocumentClick",value:function e(){this.getAdditionalFilterMenu().close()}},{key:"setCurrentFieldId",value:function e(t){this.cache.set("currentFieldId",t)}},{key:"getCurrentFieldId",value:function e(){return this.cache.get("currentFieldId","")}},{key:"setCurrentFieldNode",value:function e(t){this.cache.set("currentFieldNode",t)}},{key:"getCurrentFieldNode",value:function e(){return this.cache.get("currentFieldNode")}},{key:"onAdditionalFilterButtonClick",value:function e(t,i){i.stopPropagation();var s=i.currentTarget;this.setCurrentFieldId(t);this.setCurrentFieldNode(s.parentElement);var a=this.getAdditionalFilterMenu();var r=String(n.Dom.attr(s,"data-allowed-types")).split(",");a.getMenuItems().forEach((function(e){var t=e.getId();if(r.includes(t)||t==="helper"||t==="delimiter"){n.Dom.removeClass(e.layout.item,"main-ui-disable")}else{n.Dom.addClass(e.layout.item,"main-ui-disable")}}));if(a.getPopupWindow().isShown()){if(a.getPopupWindow().bindElement!==s){a.getPopupWindow().setBindElement(s);a.getPopupWindow().adjustPosition()}else{a.close()}}else{a.getPopupWindow().setBindElement(s);a.show()}}},{key:"getAdditionalFilterButton",value:function e(i){var s=this;var a=i.fieldId,r=i.enabled;return this.cache.remember("field_".concat(a),(function(){var e=!n.Type.isArrayFilled(r)&&r!==true;var i=function(){if(n.Type.isArrayFilled(r)){return r.join(",")}if(!e){return[t.Type.IS_EMPTY,t.Type.HAS_ANY_VALUE].join(",")}return""}();return n.Tag.render(F||(F=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<span \n\t\t\t\t\tclass="ui-icon ui-icon-service-light-other main-ui-filter-additional-filters-button','"\n\t\t\t\t\tonclick="','"\n\t\t\t\t\tdata-allowed-types="','"\n\t\t\t\t>\n\t\t\t\t\t<i></i>\n\t\t\t\t</span>\n\t\t\t'])),e?" main-ui-disable":"",s.onAdditionalFilterButtonClick.bind(s,a),i)}))}},{key:"initAdditionalFilter",value:function e(t,i){var s=this.getCurrentFieldId();if(s===""){s=t.attributes[1].value}var a=this.getAdditionalFilterPlaceholderField(s,i);n.Dom.addClass(t,"main-ui-filter-field-with-additional-filter");var r=t.querySelector(".main-ui-filter-additional-filter-placeholder");if(r){n.Dom.replace(r,a)}else{n.Dom.append(a,t)}}},{key:"restoreField",value:function e(t){if(n.Type.isDomNode(t)){var i=t.querySelector(".main-ui-filter-additional-filter-placeholder");if(i){n.Dom.remove(i)}n.Dom.removeClass(t,"main-ui-filter-field-with-additional-filter")}}},{key:"getAdditionalFilterPlaceholderField",value:function e(i,s){var a=this;return this.cache.remember("placeholder_".concat(i,"_").concat(s),(function(){var e=function(){if(s===t.Type.HAS_ANY_VALUE){return n.Loc.getMessage("MAIN_UI_FILTER__ADDITIONAL_FILTER_PLACEHOLDER_HAS_ANY_VALUE")}return n.Loc.getMessage("MAIN_UI_FILTER__ADDITIONAL_FILTER_PLACEHOLDER_IS_EMPTY")}();var i=function e(t){a.restoreField(t.currentTarget.closest(".main-ui-filter-field-with-additional-filter"))};return n.Tag.render(D||(D=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="main-ui-control main-ui-filter-additional-filter-placeholder" data-type="','">\n\t\t\t\t\t<div class="main-ui-square">\n\t\t\t\t\t\t<div class="main-ui-square-item">','</div>\n\t\t\t\t\t\t<div class="main-ui-item-icon main-ui-square-delete" onclick="','"></div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t'])),s,e,i)}))}},{key:"getFilter",value:function e(t){if(n.Type.isDomNode(t)){var i=t.querySelector(".main-ui-filter-additional-filter-placeholder");if(n.Type.isDomNode(i)){var s=n.Dom.attr(i,"data-type");var a=n.Dom.attr(t,"data-name");return babelHelpers.defineProperty({},"".concat(a,"_").concat(s),"y")}}return null}}]);return t}(i.EventEmitter);babelHelpers.defineProperty(N,"Type",{IS_EMPTY:"isEmpty",HAS_ANY_VALUE:"hasAnyValue"});babelHelpers.defineProperty(N,"cache",new n.Cache.MemoryCache);var U;function O(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,s)}return i}function R(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?O(Object(i),!0).forEach((function(t){babelHelpers.defineProperty(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):O(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}var k=new WeakMap;var M=new WeakMap;var V=new WeakMap;var w=function(){function e(t){babelHelpers.classCallCheck(this,e);this.parent=null;this.init(t)}babelHelpers.createClass(e,[{key:"init",value:function e(t){this.parent=t;BX.addCustomEvent(window,"UI::Select::change",this._onDateTypeChange.bind(this))}},{key:"deleteField",value:function e(t){n.Dom.remove(t)}},{key:"isFieldDelete",value:function e(t){return n.Dom.hasClass(t,this.parent.settings.classFieldDelete)}},{key:"isFieldValueDelete",value:function e(t){return n.Dom.hasClass(t,this.parent.settings.classValueDelete)||n.Dom.hasClass(t.parentNode,this.parent.settings.classValueDelete)}},{key:"isDragButton",value:function e(t){return t&&n.Dom.hasClass(t,this.parent.settings.classPresetDragButton)}},{key:"clearFieldValue",value:function e(t){if(t){var i=babelHelpers.toConsumableArray(t.querySelectorAll(".main-ui-control"));var s=babelHelpers.toConsumableArray(t.querySelectorAll(".main-ui-square"));s.forEach((function(e){return n.Dom.remove(e)}));i.forEach((function(e){if(Reflect.has(e,"value")){e.value=""}}))}}},{key:"getField",value:function e(t){if(n.Type.isDomNode(t)){return t.closest(".main-ui-control-field, .main-ui-control-field-group")}return null}},{key:"render",value:function e(t,i){if(n.Type.isString(t)&&n.Type.isPlainObject(i)){var s=Object.entries(i).reduce((function(e,t){var i=babelHelpers.slicedToArray(t,2),s=i[0],n=i[1];return e.replace(new RegExp("{{".concat(s,"}}"),"g"),n)}),t);var a=n.Dom.create("div",{html:s});var r=a.querySelector(".main-ui-control-field-group");if(r){return r}var l=a.querySelector(".main-ui-control-field");if(l){return l}var o=a.querySelector(".main-ui-filter-field-line");if(o){return o}}return null}},{key:"createInputText",value:function e(t){var i={block:"main-ui-control-field",mix:this.parent.getParam("ENABLE_LABEL")?[this.parent.settings.classFieldWithLabel]:null,deleteButton:true,valueDelete:true,name:t.NAME,type:t.TYPE,label:this.parent.getParam("ENABLE_LABEL")?t.LABEL:"",icon:this.parent.getParam("ENABLE_LABEL")&&t.ICON?t.ICON:null,dragTitle:this.parent.getParam("MAIN_UI_FILTER__DRAG_FIELD_TITLE"),deleteTitle:this.parent.getParam("MAIN_UI_FILTER__REMOVE_FIELD"),content:[{block:"main-ui-control-string",name:t.NAME,placeholder:t.PLACEHOLDER||"",value:n.Type.isString(t.VALUE)||n.Type.isNumber(t.VALUE)?t.VALUE:"",tabindex:t.TABINDEX}]};var s=BX.decl(i);this.parent.getEmitter().emit("init",{field:new S({parent:this.parent,options:R({},t),node:s})});return s}},{key:"createTextarea",value:function e(t){var i=BX.decl({block:"main-ui-control-field",mix:this.parent.getParam("ENABLE_LABEL")?[this.parent.settings.classFieldWithLabel]:null,deleteButton:true,valueDelete:true,name:t.NAME,type:t.TYPE,label:this.parent.getParam("ENABLE_LABEL")?t.LABEL:"",icon:this.parent.getParam("ENABLE_LABEL")&&t.ICON?t.ICON:null,dragTitle:this.parent.getParam("MAIN_UI_FILTER__DRAG_FIELD_TITLE"),deleteTitle:this.parent.getParam("MAIN_UI_FILTER__REMOVE_FIELD"),content:[{block:"main-ui-control-textarea",name:t.NAME,placeholder:t.PLACEHOLDER||"",value:n.Type.isString(t.VALUE)||n.Type.isNumber(t.VALUE)?t.VALUE:"",tabindex:t.TABINDEX}]});var s=i.querySelector("textarea");var a=function e(){n.Dom.style(s,"height","1px");n.Dom.style(s,"height","".concat(s.scrollHeight,"px"))};n.Event.bind(s,"input",a);n.Event.bind(s,"change",a);n.Event.bind(s,"keyup",a);n.Event.bind(s,"cut",a);n.Event.bind(s,"paste",a);this.parent.getEmitter().emit("init",{field:new S({parent:this.parent,options:R({},t),node:i})});return i}},{key:"createCustomEntityFieldLayout",value:function e(t){var i={block:"main-ui-control-field",mix:this.parent.getParam("ENABLE_LABEL")?[this.parent.settings.classFieldWithLabel]:null,deleteButton:true,valueDelete:true,name:t.NAME,type:t.TYPE,label:this.parent.getParam("ENABLE_LABEL")?t.LABEL:"",icon:this.parent.getParam("ENABLE_LABEL")&&t.ICON?t.ICON:null,dragTitle:this.parent.getParam("MAIN_UI_FILTER__DRAG_FIELD_TITLE"),deleteTitle:this.parent.getParam("MAIN_UI_FILTER__REMOVE_FIELD"),content:{block:"main-ui-control-entity",mix:"main-ui-control",attrs:{"data-multiple":JSON.stringify(t.MULTIPLE)},content:[]}};if("_label"in t.VALUES&&!!t.VALUES._label){if(t.MULTIPLE){var s=t.VALUES._label?t.VALUES._label:[];if(n.Type.isPlainObject(s)){s=Object.keys(s).map((function(e){return s[e]}))}if(!n.Type.isArray(s)){s=[s]}var a=t.VALUES._value?t.VALUES._value:[];if(n.Type.isPlainObject(a)){a=Object.keys(a).map((function(e){return a[e]}))}if(!n.Type.isArray(a)){a=[a]}s.forEach((function(e,t){i.content.content.push({block:"main-ui-square",tag:"span",name:e,item:{_label:e,_value:a[t]}})}))}else{i.content.content.push({block:"main-ui-square",tag:"span",name:"_label"in t.VALUES?t.VALUES._label:"",item:t.VALUES})}}i.content.content.push({block:"main-ui-square-search",tag:"span",content:{block:"main-ui-control-string",name:"".concat(t.NAME,"_label"),tabindex:t.TABINDEX,type:"text",placeholder:t.PLACEHOLDER||""}},{block:"main-ui-control-string",name:t.NAME,type:"hidden",placeholder:t.PLACEHOLDER||"",value:"_value"in t.VALUES?t.VALUES._value:"",tabindex:t.TABINDEX});i=BX.decl(i);var r=BX.Filter.Utils.getBySelector(i,'.main-ui-control-string[type="text"]');BX.addClass(r,"main-ui-square-search-item");r.autocomplete="off";n.Event.bind(r,"focus",BX.proxy(this._onCustomEntityInputFocus,this));n.Event.bind(r,"click",BX.proxy(this._onCustomEntityInputClick,this));if(!this.bindDocument){n.Event.bind(document,"click",BX.proxy(this._onCustomEntityBlur,this));document.addEventListener("focus",BX.proxy(this._onDocumentFocus,this),true);this.bindDocument=true}n.Event.bind(r,"keydown",BX.proxy(this._onCustomEntityKeydown,this));n.Event.bind(i,"click",BX.proxy(this._onCustomEntityFieldClick,this));return i}},{key:"createDestSelector",value:function e(t){var i=this.createCustomEntityFieldLayout(t);BX.ready(BX.proxy((function(){BX.Filter.DestinationSelector.create(t.NAME,{filterId:this.parent.getParam("FILTER_ID"),fieldId:t.NAME})}),this));this.parent.getEmitter().emit("init",{field:new S({parent:this.parent,options:R({},t),node:i})});return i}},{key:"createEntitySelector",value:function e(t){var i=this.createCustomEntityFieldLayout(t);BX.Filter.EntitySelector.create(t.NAME,{filter:this.parent,isMultiple:t.MULTIPLE,addEntityIdToResult:t.ADD_ENTITY_ID_TO_RESULT,showDialogOnEmptyInput:t.SHOW_DIALOG_ON_EMPTY_INPUT,dialogOptions:t.DIALOG_OPTIONS});this.parent.getEmitter().emit("init",{field:new S({parent:this.parent,options:R({},t),node:i})});return i}},{key:"createCustomEntity",value:function e(t){var i=this.createCustomEntityFieldLayout(t);this.parent.getEmitter().emit("init",{field:new S({parent:this.parent,options:R({},t),node:i})});return i}},{key:"_onCustomEntityInputFocus",value:function e(t){BX.fireEvent(t.currentTarget,"click")}},{key:"_onCustomEntityInputClick",value:function e(t){t.preventDefault();t.stopPropagation();if(t.isTrusted){this.trustTimestamp=t.timeStamp;this.notTrustTimestamp=this.notTrustTimestamp||t.timeStamp}else{this.notTrustTimestamp=t.timeStamp}var i=new Date(this.trustTimestamp);var s=new Date(this.notTrustTimestamp);var n="".concat(i.getMinutes(),":").concat(i.getSeconds());var a="".concat(s.getMinutes(),":").concat(s.getSeconds());if(n!==a){this._onCustomEntityFocus(t)}}},{key:"_onDocumentFocus",value:function e(t){var i=this.getCustomEntityInstance();var s=i.getPopupContainer();var n=i.getLabelNode()===t.target;var a=!!s&&s.contains(t.target);if(!n&&!a){this._onCustomEntityBlur(t)}}},{key:"_onCustomEntityKeydown",value:function e(t){var i=t.target,s=t.currentTarget;var a=i.parentNode.parentNode;var r=a.querySelectorAll(".main-ui-square");var l=r[r.length-1];if(!n.Type.isDomNode(l)){return}if(BX.Filter.Utils.isKey(t,"backspace")&&s.selectionStart===0){if(n.Dom.hasClass(l,"main-ui-square-selected")){var o=a.querySelector('input[type="hidden"]');if(n.Type.isDomNode(o)){o.value="";BX.fireEvent(o,"input")}n.Dom.remove(l);return}n.Dom.addClass(l,"main-ui-square-selected");return}n.Dom.removeClass(l,"main-ui-square-selected")}},{key:"_onCustomEntityFieldClick",value:function e(t){var i=t.target;if(n.Dom.hasClass(i,"main-ui-square-delete")){var s=i.closest(".main-ui-square");if(n.Type.isDomNode(s)){var a=this.getCustomEntityInstance();BX.onCustomEvent(window,"BX.Main.Filter:customEntityRemove",[a]);n.Dom.remove(s)}return}var r=i.querySelector('input[type="text"]');if(n.Type.isDomNode(r)){BX.fireEvent(r,"focus")}}},{key:"_onCustomEntityBlur",value:function e(t){var i={stopBlur:false};BX.onCustomEvent(window,"BX.Main.Filter:onGetStopBlur",[t,i]);if(typeof i.stopBlur==="undefined"||!i.stopBlur){var s=this.getCustomEntityInstance();BX.onCustomEvent(window,"BX.Main.Filter:customEntityBlur",[s]);n.Event.unbind(s.getPopupContainer(),"click",this._stopPropagation);n.Dom.removeClass(s.getField(),"main-ui-focus")}}},{key:"_stopPropagation",value:function e(t){t.stopPropagation()}},{key:"getCustomEntityInstance",value:function e(){if(!(this.customEntityInstance instanceof BX.Main.ui.CustomEntity)){this.customEntityInstance=new BX.Main.ui.CustomEntity}return this.customEntityInstance}},{key:"_onCustomEntityFocus",value:function e(t){t.stopPropagation();var i=t.currentTarget;var s=i.closest(".main-ui-control-entity");var a=this.getCustomEntityInstance();a.setField(s);BX.onCustomEvent("BX.Main.Filter:customEntityFocus",[a]);var r=a.getPopupContainer();if(n.Type.isElementNode(r)){n.Event.bind(r,"click",this._stopPropagation)}n.Dom.addClass(s,"main-ui-focus")}},{key:"createCustom",value:function e(t){var i=BX.decl({block:"main-ui-control-field",mix:this.parent.getParam("ENABLE_LABEL")?[this.parent.settings.classFieldWithLabel]:null,name:t.NAME,type:t.TYPE,deleteButton:true,label:this.parent.getParam("ENABLE_LABEL")?t.LABEL:"",icon:this.parent.getParam("ENABLE_LABEL")&&t.ICON?t.ICON:null,dragTitle:this.parent.getParam("MAIN_UI_FILTER__DRAG_FIELD_TITLE"),deleteTitle:this.parent.getParam("MAIN_UI_FILTER__REMOVE_FIELD"),content:{block:"main-ui-custom",mix:["main-ui-control","main-ui-custom-style"],attrs:{"data-name":t.NAME},content:""}});if(n.Type.isString(t.VALUE)){var s=function(){if(Reflect.has(t,"_VALUE")){return t._VALUE}return""}();var a=n.Text.decode(t.VALUE).replace('name="'.concat(t.NAME,'"'),'name="'.concat(t.NAME,'" value="').concat(s,'"'));var r=i.querySelector(".main-ui-custom");n.Runtime.html(r,a)}this.parent.getEmitter().emit("init",{field:new S({parent:this.parent,options:R({},t),node:i})});return i}},{key:"createSelect",value:function e(t){var i=BX.decl({block:"main-ui-control-field",mix:this.parent.getParam("ENABLE_LABEL")?[this.parent.settings.classFieldWithLabel]:null,name:t.NAME,type:t.TYPE,deleteButton:true,label:this.parent.getParam("ENABLE_LABEL")?t.LABEL:"",icon:this.parent.getParam("ENABLE_LABEL")&&t.ICON?t.ICON:null,dragTitle:this.parent.getParam("MAIN_UI_FILTER__DRAG_FIELD_TITLE"),deleteTitle:this.parent.getParam("MAIN_UI_FILTER__REMOVE_FIELD"),content:{block:this.parent.settings.classSelect,name:t.NAME,items:t.ITEMS,value:"VALUE"in t?t.VALUE:t.ITEMS[0],params:t.PARAMS,tabindex:t.TABINDEX,valueDelete:false}});this.parent.getEmitter().emit("init",{field:new S({parent:this.parent,options:R({},t),node:i})});return i}},{key:"createMultiSelect",value:function e(t){var i=BX.decl({block:"main-ui-control-field",mix:this.parent.getParam("ENABLE_LABEL")?[this.parent.settings.classFieldWithLabel]:null,name:t.NAME,type:t.TYPE,deleteButton:true,label:this.parent.getParam("ENABLE_LABEL")?t.LABEL:"",icon:this.parent.getParam("ENABLE_LABEL")&&t.ICON?t.ICON:null,dragTitle:this.parent.getParam("MAIN_UI_FILTER__DRAG_FIELD_TITLE"),deleteTitle:this.parent.getParam("MAIN_UI_FILTER__REMOVE_FIELD"),content:{block:"main-ui-multi-select",name:t.NAME,tabindex:"TABINDEX"in t?t.TABINDEX:"",placeholder:!this.parent.getParam("ENABLE_LABEL")&&"PLACEHOLDER"in t?t.PLACEHOLDER:"",items:"ITEMS"in t?t.ITEMS:[],value:"VALUE"in t?t.VALUE:[],params:"PARAMS"in t?t.PARAMS:{isMulti:true},valueDelete:true}});this.parent.getEmitter().emit("init",{field:new S({parent:this.parent,options:R({},t),node:i})});return i}},{key:"createCustomDate",value:function e(t){var i={block:"main-ui-control-field-group",type:t.TYPE,mix:this.parent.getParam("ENABLE_LABEL")?[this.parent.settings.classFieldWithLabel,"main-ui-filter-date-group"]:["main-ui-filter-date-group"],label:this.parent.getParam("ENABLE_LABEL")?t.LABEL:"",icon:this.parent.getParam("ENABLE_LABEL")&&t.ICON?t.ICON:null,dragTitle:this.parent.getParam("MAIN_UI_FILTER__DRAG_FIELD_TITLE"),deleteTitle:this.parent.getParam("MAIN_UI_FILTER__REMOVE_FIELD"),tabindex:"TABINDEX"in t?t.TABINDEX:"",name:"NAME"in t?t.NAME:"",deleteButton:true,content:[]};if(n.Type.isPlainObject(t.VALUE.days)){t.VALUE.days=Object.keys(t.VALUE.days).map((function(e){return t.VALUE.days[e]}))}var s=t.DAYS.filter((function(e){return t.VALUE.days.some((function(t){return t===e.VALUE}))}));var a={block:"main-ui-control-field",mix:["main-ui-control-custom-date"],placeholder:t.DAYS_PLACEHOLDER,dragButton:false,content:{block:"main-ui-multi-select",name:"".concat(t.NAME,"_days"),tabindex:"TABINDEX"in t?t.TABINDEX:"",items:t.DAYS,value:s,params:"PARAMS"in t?t.PARAMS:{isMulti:true},valueDelete:true,attrs:{"data-placeholder":t.DAYS_PLACEHOLDER}}};if(n.Type.isPlainObject(t.VALUE.months)){t.VALUE.months=Object.keys(t.VALUE.months).map((function(e){return t.VALUE.months[e]}))}var r=t.MONTHS.filter((function(e){return t.VALUE.months.some((function(t){return t===e.VALUE}))}));var l={block:"main-ui-control-field",mix:["main-ui-control-custom-date"],dragButton:false,content:{block:"main-ui-multi-select",name:"".concat(t.NAME,"_months"),tabindex:"TABINDEX"in t?t.TABINDEX:"",items:t.MONTHS,value:r,params:"PARAMS"in t?t.PARAMS:{isMulti:true},valueDelete:true,attrs:{"data-placeholder":t.MONTHS_PLACEHOLDER}}};if(n.Type.isPlainObject(t.VALUE.years)){t.VALUE.years=Object.keys(t.VALUE.years).map((function(e){return t.VALUE.years[e]}))}var o=t.YEARS.filter((function(e){return t.VALUE.years.some((function(t){return t===e.VALUE}))}));var u={block:"main-ui-control-field",mix:["main-ui-control-custom-date"],dragButton:false,content:{block:"main-ui-multi-select",name:"".concat(t.NAME,"_years"),tabindex:"TABINDEX"in t?t.TABINDEX:"",items:t.YEARS,value:o,params:"PARAMS"in t?t.PARAMS:{isMulti:true},valueDelete:true,attrs:{"data-placeholder":t.YEARS_PLACEHOLDER}}};i.content.push(a);i.content.push(l);i.content.push(u);var c=BX.decl(i);this.parent.getEmitter().emit("init",{field:new S({parent:this.parent,options:R({},t),node:c})});return c}},{key:"_onDateTypeChange",value:function e(t,i){var s=this;if(this.parent.getPopup().contentContainer.contains(t.node)){var a={};var r=null;var l;var o;var u;if(n.Type.isPlainObject(i)&&Reflect.has(i,"VALUE")){var c=t.getNode();var d=t.getParams();var h=c.dataset.name;if(!n.Type.isPlainObject(d)&&(h.endsWith("_datesel")||h.endsWith("_numsel"))){var p=c.parentNode.parentNode;a.TABINDEX=t.getInput().getAttribute("tabindex");a.SUB_TYPES=t.getItems();a.SUB_TYPE=i;a.NAME=p.dataset.name;a.TYPE=p.dataset.type;a.VALUE_REQUIRED=p.dataset.valueRequired==="true";var f=this.parent.getPreset().getCurrentPresetData();if(n.Type.isArray(f.FIELDS)){var m=f.FIELDS.find((function(e){return e.NAME===a.NAME}));if(n.Type.isNil(m)){m=this.parent.params.FIELDS_STUBS.find((function(e){return e.TYPE===a.TYPE}))}if(!n.Type.isNil(m)){if(h.endsWith("_datesel")){a.MONTHS=m.MONTHS;a.MONTH=m.MONTH;a.YEARS=m.YEARS;a.YEAR=m.YEAR;a.QUARTERS=m.QUARTERS;a.QUARTER=m.QUARTER;a.ENABLE_TIME=m.ENABLE_TIME;a.YEARS_SWITCHER=m.YEARS_SWITCHER}a.VALUES=m.VALUES;a.REQUIRED=m.REQUIRED}}if(this.parent.getParam("ENABLE_LABEL")){l=p.querySelector(".main-ui-control-field-label");a.LABEL=l.innerText}if(h.endsWith("_datesel")){r=this.createDate(a)}else{r=this.createNumber(a)}if(n.Type.isArray(this.parent.fieldsList)){u=this.parent.fieldsList.indexOf(p);if(u!==-1){this.parent.fieldsList[u]=r;this.parent.registerDragItem(r)}}this.parent.unregisterDragItem(p);o=babelHelpers.toConsumableArray(r.querySelectorAll(".main-ui-control-field"));if(n.Type.isArray(o)&&o.length){o.forEach((function(e){e.FieldController=new BX.Filter.FieldController(e,s.parent)}))}if(this.parent.getParam("ENABLE_ADDITIONAL_FILTERS")){var E=N.getInstance().getAdditionalFilterButton({fieldId:a.NAME,enabled:a.ADDITIONAL_FILTER_ALLOWED});n.Dom.append(E,r)}n.Dom.insertAfter(r,p);n.Dom.remove(p)}}}}},{key:"createNumber",value:function e(t){var i=this.parent,s=i.numberTypes,n=i.additionalNumberTypes;var a=this.parent.params.ENABLE_LABEL;var r=t.SUB_TYPE,l=r===void 0?{}:r,o=t.SUB_TYPES,u=o===void 0?[]:o,c=t.TABINDEX,d=c===void 0?"":c,h=t.VALUES,p=h===void 0?{_from:"",_to:""}:h,f=t.LABEL,m=f===void 0?"":f,E=t.ICON,g=E===void 0?null:E,y=t.TYPE;var v=l.VALUE||s.SINGLE;var B=l.PLACEHOLDER||"";var A=t.NAME.replace("_numsel","");var P=function(){if(a){return["main-ui-filter-wield-with-label","main-ui-filter-number-group"]}return["main-ui-filter-number-group"]}();var _={block:"number-group",type:y,mix:P,label:a?m:"",icon:a?g:null,dragTitle:this.parent.getParam("MAIN_UI_FILTER__DRAG_FIELD_TITLE"),deleteTitle:this.parent.getParam("MAIN_UI_FILTER__REMOVE_FIELD"),tabindex:d,value:l,items:u,name:A,deleteButton:true,content:[]};if(v!==s.LESS&&v!==n.BEFORE_N){var L={block:"main-ui-control-field",type:y,dragButton:false,content:{block:"main-ui-number",mix:["filter-type-single"],calendarButton:true,valueDelete:true,placeholder:B,name:"".concat(A,"_from"),tabindex:d,value:p._from||""}};_.content.push(L)}if(v===s.RANGE){var b={block:"main-ui-filter-field-line",content:{block:"main-ui-filter-field-line-item",tag:"span"}};_.content.push(b)}if(v===s.RANGE||v===s.LESS||v===n.BEFORE_N){var I={block:"main-ui-control-field",type:y,dragButton:false,content:{block:"main-ui-number",calendarButton:true,valueDelete:true,name:"".concat(A,"_to"),tabindex:d,value:p._to||""}};_.content.push(I)}var T=BX.decl(_);this.parent.getEmitter().emit("init",{field:new S({parent:this.parent,options:R({},t),node:T})});return T}},{key:"createDate",value:function e(t){var i=this;var s=this.parent,a=s.dateTypes,r=s.additionalDateTypes;var l=t.SUB_TYPE,o=l===void 0?{}:l,u=t.SUB_TYPES,c=u===void 0?[]:u,d=t.PLACEHOLDER,h=d===void 0?"":d,p=t.VALUES,f=p===void 0?{_from:"",_to:"",_quarter:"",_days:"",_month:"",_year:"",_allow_year:""}:p,m=t.TABINDEX,E=m===void 0?"":m,g=t.ENABLE_TIME,y=g===void 0?false:g,v=t.LABEL,B=v===void 0?"":v,A=t.ICON,P=A===void 0?null:A,_=t.TYPE,F=t.VALUE_REQUIRED,D=F===void 0?false:F,X=t.REQUIRED,C=X===void 0?false:X;var N=this.parent.params.ENABLE_LABEL;var U=o.VALUE||a.NONE;var O=t.NAME.replace("_datesel","");var k=function(){if(N){return["main-ui-filter-wield-with-label","main-ui-filter-date-group"]}return["main-ui-filter-date-group"]}();var M={block:"date-group",type:_,mix:k,label:N?B:"",icon:N?P:null,dragTitle:this.parent.getParam("MAIN_UI_FILTER__DRAG_FIELD_TITLE"),deleteTitle:this.parent.getParam("MAIN_UI_FILTER__REMOVE_FIELD"),tabindex:E,value:o,items:c,name:O,enableTime:y,deleteButton:true,content:[]};if(U===a.EXACT){var V=L({type:_,name:"".concat(O.NAME,"_from"),placeholder:h,tabindex:E,value:f._from||"",enableTime:y});M.content.push(V)}if(U===a.NEXT_DAYS||U===a.PREV_DAYS||U===r.PREV_DAY||U===r.NEXT_DAY||U===r.MORE_THAN_DAYS_AGO||U===r.AFTER_DAYS){var w=b({type:_,name:"".concat(O,"_days"),tabindex:E,value:f._days||"",placeholder:h});M.content.push(w)}if(U===a.RANGE){var x={block:"main-ui-filter-range-group",content:[L({type:_,name:"".concat(O,"_from"),placeholder:h,tabindex:E,value:f._from||"",enableTime:y}),I(),L({type:_,name:"".concat(O,"_to"),placeholder:h,tabindex:E,value:f._to||"",enableTime:y})]};M.content.push(x)}if(U===a.MONTH){var j=t.MONTHS,q=t.MONTH,Y=t.YEARS,H=t.YEAR;var W=j.find((function(e){return e.VALUE===f._month}))||q||j[0];var G=Y.find((function(e){return e.VALUE===f._year}))||H||Y[0];M.content.push(T({name:"".concat(O,"_month"),value:W,items:j,tabindex:E}),T({name:"".concat(O,"_year"),value:G,items:Y,tabindex:E}))}if(U===a.QUARTER){var Q=t.YEARS,K=t.YEAR,J=t.QUARTERS,z=t.QUARTER,Z=t.PARAMS;var $=Q.find((function(e){return e.VALUE===f._year}))||K||Q[0];var ee=J.find((function(e){return e.VALUE===f._quarter}))||z||J[0];M.content.push(T({name:"".concat(O,"_year"),value:$,items:Q,tabindex:E}),T({name:"".concat(O,"_quarter"),value:ee,items:J,tabindex:E,params:Z}))}if(U===a.YEAR){var te=t.YEARS,ie=t.YEAR;var se=te.find((function(e){return e.VALUE===f._year}))||ie||te[0];M.content.push(T({name:"".concat(O,"_year"),value:se,items:te,tabindex:E}))}if(U==="CUSTOM_DATE"){var ne=c.find((function(e){return e.VALUE==="CUSTOM_DATE"}));if(ne){var ae=n.Runtime.clone(ne.DECL);if(n.Type.isArray(f._days)){ae.VALUE.days=f._days}if(n.Type.isArray(f._month)){ae.VALUE.months=f._month}if(n.Type.isArray(f._year)){ae.VALUE.years=f._year}var re=this.createCustomDate(ae);n.Dom.removeClass(re,"main-ui-filter-wield-with-label");var le=babelHelpers.toConsumableArray(re.querySelectorAll(".main-ui-item-icon-container, .main-ui-filter-icon-grab"));le.forEach((function(e){return n.Dom.remove(e)}));M.content.push(re);M.mix.push("main-ui-filter-custom-date-group")}}if(U!==a.NONE&&U!==r.CUSTOM_DATE&&t.YEARS_SWITCHER){var oe=n.Runtime.clone(t.YEARS_SWITCHER);var ue=oe.ITEMS;oe.VALUE=ue.reduce((function(e,t){return t.VALUE===f._allow_year?t:e}));var ce=this.createSelect(oe);n.Dom.addClass(ce,["main-ui-filter-year-switcher","main-ui-filter-with-padding"]);n.Dom.removeClass(ce,"main-ui-filter-wield-with-label");var de=babelHelpers.toConsumableArray(ce.querySelectorAll(".main-ui-item-icon-container, .main-ui-filter-icon-grab"));de.forEach((function(e){return n.Dom.remove(e)}));var he=M.content.length-1;var pe=M.content[he];if(n.Type.isPlainObject(pe)){if(!n.Type.isArray(pe.mix)){pe.mix=[]}pe.mix.push("main-ui-filter-remove-margin-right")}if(n.Type.isDomNode(pe)){n.Dom.addClass(pe,"main-ui-filter-remove-margin-right")}requestAnimationFrame((function(){n.Dom.addClass(ce.previousElementSibling,"main-ui-filter-remove-margin-right")}));M.content.push(ce);M.mix.push("main-ui-filter-date-with-years-switcher")}var fe=BX.decl(M);var me=n.Runtime.debounce(this.onDateChange,500,this);var Ee=babelHelpers.toConsumableArray(fe.querySelectorAll(".main-ui-date-input"));Ee.forEach((function(e){e.addEventListener("change",me);e.addEventListener("input",me);var t=e.parentNode;var s=t.querySelector(".main-ui-control-value-delete");if(s){s.addEventListener("click",(function(){setTimeout((function(){i.onDateChange({target:e})}))}))}}));if(D){fe.dataset.valueRequired=true;var ge=[].concat(babelHelpers.toConsumableArray(Ee),babelHelpers.toConsumableArray(fe.querySelectorAll(".main-ui-number-input")));ge.forEach((function(e){e.addEventListener("change",i.checkRequiredDateValue.bind(i));e.addEventListener("input",i.checkRequiredDateValue.bind(i));var t=e.parentNode;var s=t.querySelector(".main-ui-control-value-delete");if(s){s.addEventListener("click",(function(){setTimeout((function(){i.checkRequiredDateValue({target:e})}))}))}n.Event.bindOnce(e,"mouseout",(function(){i.checkRequiredDateValue({target:e})}))}))}if(C){var ye=fe.querySelector(".main-ui-filter-field-delete");if(ye){BX.remove(ye)}}var ve={};this.parent.prepareControlDateValue(ve,O,fe);Object.entries(ve).forEach((function(e){var t=babelHelpers.slicedToArray(e,2),i=t[0],s=t[1];ve[i.replace(O,"")]=s;delete ve[i]}));this.parent.getEmitter().emit("init",{field:new S({parent:this.parent,options:R(R({},t),{},{VALUES:ve}),node:fe})});return fe}},{key:"checkRequiredDateValue",value:function e(t){if(t.target.value===""){this.showError({id:"valueError",target:t.target,text:this.parent.params.MAIN_UI_FILTER__VALUE_REQUIRED});return}this.hideError({id:"valueError",target:t.target})}},{key:"onDateChange",value:function e(t){var i=this;if(V.get(t.target)===t.target.value){return}V.set(t.target,t.target.value);if(t.target.value===""){this.hideError({id:"formatError",target:t.target});return}BX.ajax.runComponentAction("bitrix:main.ui.filter","checkDateFormat",{mode:"ajax",data:{value:t.target.value,format:BX.message("FORMAT_DATETIME")}}).then((function(e){if(!e.data.result){i.showError({id:"formatError",target:t.target});return}i.hideError({id:"formatError",target:t.target})}))}},{key:"showError",value:function e(t){var i=t.id,s=t.target,a=t.text,r=a===void 0?null:a;n.Dom.style(s,"border-color","#FF5752");if(k.has(s)&&M.get(s)===i){n.Dom.remove(k.get(s))}var l=this.parent.params,o=l.MAIN_UI_FILTER__DATE_ERROR_TITLE,u=l.MAIN_UI_FILTER__DATE_ERROR_LABEL;var c=r||"".concat(u," ").concat(n.Loc.getMessage("FORMAT_DATE"));var d=n.Tag.render(U||(U=babelHelpers.taggedTemplateLiteral(['\n\t\t\t<div \n\t\t\t\tclass="main-ui-filter-error-message" \n\t\t\t\ttitle="','">\n\t\t\t\t',"\n\t\t\t</div>\n\t\t"])),o,c);k.set(s,d);M.set(s,i);n.Dom.insertAfter(d,s);n.Dom.attr(s,"is-valid","false")}},{key:"hideError",value:function e(t){var i=t.id,s=t.target;n.Dom.style(s,"border-color",null);if(k.has(s)&&M.get(s)===i){n.Dom.remove(k.get(s))}n.Dom.attr(s,"is-valid","true")}}]);return e}();var x=function(){function e(t){babelHelpers.classCallCheck(this,e);this.parent=null;this.presets=null;this.container=null;this.init(t)}babelHelpers.createClass(e,[{key:"init",value:function e(t){this.parent=t}},{key:"bindOnPresetClick",value:function e(){var t=this;(this.getPresets()||[]).forEach((function(e){n.Event.bind(e,"click",BX.delegate(t._onPresetClick,t))}))}},{key:"getAddPresetField",value:function e(){return this.getContainer().querySelector(".main-ui-filter-new-filter")}},{key:"getAddPresetFieldInput",value:function e(){return this.getAddPresetField().querySelector(".main-ui-filter-sidebar-edit-control")}},{key:"clearAddPresetFieldInput",value:function e(){var t=this.getAddPresetFieldInput();if(n.Type.isDomNode(t)){t.value=""}}},{key:"normalizePreset",value:function e(t){return t.closest(".main-ui-filter-sidebar-item")}},{key:"deactivateAllPresets",value:function e(){this.getPresets().forEach((function(e){n.Dom.removeClass(e,"main-ui-filter-current-item")}))}},{key:"createSidebarItem",value:function e(t,i,s){return BX.decl({block:"sidebar-item",text:n.Text.decode(i),id:t,pinned:s,noEditPinTitle:this.parent.getParam("MAIN_UI_FILTER__IS_SET_AS_DEFAULT_PRESET"),editNameTitle:this.parent.getParam("MAIN_UI_FILTER__EDIT_PRESET_TITLE"),removeTitle:this.parent.getParam("MAIN_UI_FILTER__REMOVE_PRESET"),editPinTitle:this.parent.getParam("MAIN_UI_FILTER__SET_AS_DEFAULT_PRESET"),dragTitle:this.parent.getParam("MAIN_UI_FILTER__DRAG_TITLE")})}},{key:"activatePreset",value:function e(t){var i=this;this.deactivateAllPresets();var s=function(){if(n.Type.isString(t)){return i.getPresetNodeById(t)}return t}();if(n.Type.isDomNode(s)){n.Dom.addClass(s,"main-ui-filter-current-item")}}},{key:"getPresetNodeById",value:function e(t){return this.getPresets().find((function(e){return n.Dom.attr(e,"data-id")===t}))}},{key:"getPresetId",value:function e(t){return n.Dom.attr(t,"data-id")}},{key:"updatePresetName",value:function e(t,i){if(n.Type.isDomNode(t)&&n.Type.isString(i)&&i!==""){var s=this.getPresetNameNode(t);if(n.Type.isDomNode(s)){n.Runtime.html(s,i)}}}},{key:"removePreset",value:function e(t,i,s){var n=this.getCurrentPresetId();var a=[];var r={preset_id:i,is_default:s};var l={FILTER_ID:this.parent.getParam("FILTER_ID"),action:"REMOVE_FILTER"};this.parent.saveOptions(r,l);BX.remove(t);if(BX.type.isArray(this.parent.params.PRESETS)){a=this.parent.params.PRESETS.filter((function(e){return e.ID!==i}),this);this.parent.params.PRESETS=a}if(BX.type.isArray(this.parent.editablePresets)){a=this.parent.editablePresets.filter((function(e){return e.ID!==i}),this);this.parent.editablePresets=a}if(i===n){this.parent.getSearch().removePreset();this.resetPreset()}}},{key:"pinPreset",value:function e(t){if(!BX.type.isNotEmptyString(t)){t="default_filter"}var i=this.getPresetNodeById(t);if(this.parent.getParam("VALUE_REQUIRED_MODE")){if(t==="default_filter"){return}}var s={FILTER_ID:this.parent.getParam("FILTER_ID"),GRID_ID:this.parent.getParam("GRID_ID"),action:"PIN_PRESET"};var a={preset_id:t};this.getPresets().forEach((function(e){n.Dom.removeClass(e,this.parent.settings.classPinnedPreset)}),this);BX.addClass(i,this.parent.settings.classPinnedPreset);this.parent.saveOptions(a,s)}},{key:"_onPresetClick",value:function e(t){var i;var s;var a;var r;var l;var o;var u;t.preventDefault();u=this.parent;o=u.settings;l=t.target;i=t.currentTarget;s=this.getPresetId(i);a=this.getPreset(s);if(n.Dom.hasClass(l,o.classPinButton)){if(this.parent.isEditEnabled()){if(n.Dom.hasClass(i,o.classPinnedPreset)){this.pinPreset("default_filter")}else{this.pinPreset(s)}}}if(n.Dom.hasClass(l,o.classPresetEditButton)){this.enableEditPresetName(i)}if(n.Dom.hasClass(l,o.classPresetDeleteButton)){r="IS_DEFAULT"in a?a.IS_DEFAULT:false;this.removePreset(i,s,r);return false}if(!n.Dom.hasClass(l,o.classPresetDragButton)&&!n.Dom.hasClass(l,o.classAddPresetFieldInput)){if(this.parent.isEditEnabled()){this.updateEditablePreset(this.getCurrentPresetId())}var c=this.getPreset(this.getCurrentPresetId());var d=this.getPreset(s);c.ADDITIONAL=[];d.ADDITIONAL=[];this.activatePreset(i);this.applyPreset(s);if(!this.parent.isEditEnabled()){u.applyFilter(null,true);if(t.isTrusted){u.closePopup()}if(u.isAddPresetEnabled()){u.disableAddPreset()}}}}},{key:"applyPinnedPreset",value:function e(){var t=this.parent;var i=this.isPinned(this.getCurrentPresetId());var s;if(this.parent.getParam("VALUE_REQUIRED")&&this.getPinnedPresetId()==="default_filter"){this.applyPreset("default_filter");this.deactivateAllPresets();s=this.parent.applyFilter()}else if(!i){var n=this.getPinnedPresetId();var a=this.getPreset(n);a.ADDITIONAL=[];var r=this.getPinnedPresetNode();var l=false;var o=true;this.deactivateAllPresets();this.activatePreset(r);this.applyPreset(n);s=t.applyFilter(l,o);t.closePopup()}else{s=t.resetFilter()}return s}},{key:"updateEditablePreset",value:function e(t){var i=this.parent.getFilterFieldsValues();var s=this.getFields().map((function(e){return BX.data(e,"name")}));var n=this.parent.preparePresetFields(i,s);var a=this.getPreset(t);a.FIELDS=n;a.TITLE=this.getPresetInput(this.getPresetNodeById(t)).value;a.ROWS=s}},{key:"getPresetInput",value:function e(t){return BX.Filter.Utils.getByClass(t,this.parent.settings.classPresetEditInput)}},{key:"enableEditPresetName",value:function e(t){var i=this.getPresetInput(t);BX.addClass(t,this.parent.settings.classPresetNameEdit);i.select();i.value=BX.util.htmlspecialcharsback(i.value);n.Event.bind(i,"input",BX.delegate(this._onPresetNameInput,this))}},{key:"_onPresetNameInput",value:function e(t){var i=this.parent.getSearch();var s=t.currentTarget.value;var n=BX.findParent(t.currentTarget,{className:this.parent.settings.classPreset},true,false);var a=this.getPresetId(n);var r=this.getCurrentPresetId();var l={ID:a,TITLE:s};if(a===r){i.updatePreset(l)}}},{key:"getPresetNameNode",value:function e(t){return BX.Filter.Utils.getByClass(t,this.parent.settings.classPresetName)}},{key:"disableEditPresetName",value:function e(t){var i=this.getPresetInput(t);n.Dom.removeClass(t,this.parent.settings.classPresetNameEdit);if(BX.type.isDomNode(i)){i.blur();BX.unbind(i,"input",BX.delegate(this._onPresetNameInput,this))}}},{key:"getPreset",value:function e(t,i){var s=this.parent.getParam(i?"DEFAULT_PRESETS":"PRESETS",[]);if(this.parent.isEditEnabled()&&!i){s=this.parent.editablePresets}var n=s.filter((function(e){return e.ID===t}));if(t==="tmp_filter"&&!n.length){var a=BX.clone(this.getPreset("default_filter"));a.ID="tmp_filter";s.push(a);n.push(a)}return n.length!==0?n[0]:null}},{key:"getPresetField",value:function e(t,i){var s=this.getPreset(t);var n=null;if(BX.type.isPlainObject(s)&&"FIELDS"in s&&BX.type.isArray(s.FIELDS)){n=s.FIELDS.filter((function(e){return e.NAME===i}));n=n.length?n[0]:null}return n}},{key:"applyPreset",value:function e(t,i){t=i?"default_filter":t||"default_filter";var s=this.getPreset(t);if(t!=="default_preset"){s=this.extendPreset(s)}this.parent.getSearch().updatePreset(s);this.updatePresetFields(s,i);BX.onCustomEvent("BX.Main.Filter:onApplyPreset",[t])}},{key:"extendPreset",value:function e(t){var i=BX.clone(this.getPreset("default_filter"));if(BX.type.isPlainObject(t)){t=BX.clone(t);t.FIELDS.forEach((function(e){var t;var s=i.FIELDS.some((function(i,s){var n=false;if(i.NAME===e.NAME){t=s;n=true}return n}),this);if(s&&t||s&&t===0){i.FIELDS[t]=e}else if(!this.isEmptyField(e)){i.FIELDS.push(e)}}),this);t.FIELDS=i.FIELDS}return t}},{key:"isEmptyField",value:function e(t){var i=true;if(n.Type.isStringFilled(t.ADDITIONAL_FILTER)){return false}if(t.TYPE===this.parent.types.STRING){if(t.VALUE&&t.VALUE.length){i=false}}if(t.TYPE===this.parent.types.SELECT){if(BX.type.isPlainObject(t.VALUE)&&"VALUE"in t.VALUE&&t.VALUE.VALUE){i=false}}if(t.TYPE===this.parent.types.MULTI_SELECT){if(BX.type.isArray(t.VALUE)&&t.VALUE.length){i=false}}if(t.TYPE===this.parent.types.CUSTOM_DATE){if(BX.type.isArray(t.VALUE.days)&&t.VALUE.days.length||BX.type.isArray(t.VALUE.months)&&t.VALUE.months.length||BX.type.isArray(t.VALUE.years)&&t.VALUE.years.length){i=false}}if(t.TYPE===this.parent.types.CUSTOM_ENTITY||t.TYPE===this.parent.types.DEST_SELECTOR||t.TYPE===this.parent.types.ENTITY_SELECTOR){if(BX.type.isPlainObject(t.VALUES)){if(BX.type.isNotEmptyString(t.VALUES._label)&&BX.type.isNotEmptyString(t.VALUES._value)){i=false}if(BX.type.isPlainObject(t.VALUES._label)&&BX.type.isPlainObject(t.VALUES._value)&&Object.keys(t.VALUES._label).length&&Object.keys(t.VALUES._value).length){i=false}if(BX.type.isArray(t.VALUES._label)&&BX.type.isArray(t.VALUES._value)&&t.VALUES._label.length&&t.VALUES._value.length){i=false}if((BX.type.isArray(t.VALUES._label)&&t.VALUES._label.length||BX.type.isPlainObject(t.VALUES._label)&&Object.keys(t.VALUES._label).length)&&(BX.type.isArray(t.VALUES._value)&&t.VALUES._value.length||BX.type.isPlainObject(t.VALUES._value)&&Object.keys(t.VALUES._value).length)){i=false}}}if(t.TYPE===this.parent.types.DATE){var s="_datesel"in t.VALUES?t.VALUES._datesel:t.SUB_TYPE.VALUE;if(BX.type.isPlainObject(t.VALUES)&&(t.VALUES._from||t.VALUES._to||t.VALUES._quarter||t.VALUES._month&&!BX.type.isArray(t.VALUES._month)||t.VALUES._year&&!BX.type.isArray(t.VALUES._year)||t.VALUES._days&&!BX.type.isArray(t.VALUES._days))||BX.type.isArray(t.VALUES._days)&&t.VALUES._days.length||BX.type.isArray(t.VALUES._month)&&t.VALUES._month.length||BX.type.isArray(t.VALUES._year)&&t.VALUES._year.length||s===this.parent.dateTypes.CURRENT_DAY||s===this.parent.dateTypes.CURRENT_WEEK||s===this.parent.dateTypes.CURRENT_MONTH||s===this.parent.dateTypes.CURRENT_QUARTER||s===this.parent.dateTypes.LAST_7_DAYS||s===this.parent.dateTypes.LAST_30_DAYS||s===this.parent.dateTypes.LAST_60_DAYS||s===this.parent.dateTypes.LAST_90_DAYS||s===this.parent.dateTypes.LAST_WEEK||s===this.parent.dateTypes.LAST_MONTH||s===this.parent.dateTypes.TOMORROW||s===this.parent.dateTypes.YESTERDAY||s===this.parent.dateTypes.NEXT_WEEK||s===this.parent.dateTypes.NEXT_MONTH){i=false}}if(t.TYPE===this.parent.types.NUMBER){if(BX.type.isPlainObject(t.VALUES)&&(t.VALUES._from||t.VALUES._to)){i=false}}if(t.TYPE===this.parent.types.CHECKBOX){if(BX.type.isPlainObject(t.VALUE)&&t.VALUE.VALUE){i=false}}return i}},{key:"resetPreset",value:function e(t){this.applyPreset("",t)}},{key:"getFields",value:function e(){var t=this.parent.getFieldListContainer();var i=null;if(BX.type.isDomNode(t)){i=BX.Filter.Utils.getBySelector(t.parentNode,".".concat(this.parent.settings.classFileldControlList," > div"),true)}return i}},{key:"getField",value:function e(t){var i=this.getFields();var s=null;var n;var a;if(BX.type.isArray(i)&&i.length){a=i.filter((function(e){if(BX.type.isDomNode(e)){n=BX.data(e,"name")}return n===t.NAME}),this);s=a.length>0?a[0]:null}return s}},{key:"removeField",value:function e(t,i){var s;var n;i=i||false;if(BX.type.isPlainObject(t)){n=t.NAME;t=this.getField(t);if(BX.type.isArray(this.parent.fieldsList)){s=this.parent.fieldsList.indexOf(t);if(s!==-1){delete this.parent.fieldsList[s]}}this.parent.unregisterDragItem(t)}if(BX.type.isDomNode(t)){n=BX.data(t,"name");this.parent.getFields().deleteField(t)}if(!this.parent.isEditEnabled()&&!this.parent.isAddPresetEnabled()){var a=this.getCurrentPresetId();var r=this.getPresetField(a,n);if(r&&!this.isEmptyField(r)){this.deactivateAllPresets();this.parent.applyFilter()}}if(!i){this.parent.saveFieldsSort()}}},{key:"removeFields",value:function e(t){t.forEach((function(e){this.removeField(e,true)}),this);this.parent.saveFieldsSort()}},{key:"addField",value:function e(t){var i;var s;var n;if(BX.type.isPlainObject(t)){i=this.parent.getFieldListContainer();n=this.parent.getControls();s=BX.type.isArray(n)?n[n.length-1]:null;if(BX.type.isDomNode(s)){if(s.nodeName!=="INPUT"){s=BX.Filter.Utils.getByTag(s,"input")}if(BX.type.isDomNode(s)){t.TABINDEX=parseInt(s.getAttribute("tabindex"))+1}}else{t.TABINDEX=2}if(BX.type.isDomNode(i)){s=this.createControl(t);if(BX.type.isDomNode(s)){BX.append(s,i);if(BX.type.isArray(this.parent.fieldsList)){this.parent.fieldsList.push(s)}this.parent.registerDragItem(s)}}}if(!this.parent.isEditEnabled()&&!this.parent.isAddPresetEnabled()){var a=this.getCurrentPresetId();var r=this.getPresetField(a,t.NAME);if(r&&!this.isEmptyField(r)){this.parent.updatePreset("tmp_filter");this.deactivateAllPresets();this.parent.getSearch().updatePreset(this.getPreset("tmp_filter"))}}this.parent.saveFieldsSort()}},{key:"createControl",value:function e(t){var i;switch(t.TYPE){case this.parent.types.STRING:{i=this.parent.getFields().createInputText(t);break}case this.parent.types.TEXTAREA:{i=this.parent.getFields().createTextarea(t);break}case this.parent.types.SELECT:{i=this.parent.getFields().createSelect(t);break}case this.parent.types.MULTI_SELECT:{i=this.parent.getFields().createMultiSelect(t);break}case this.parent.types.NUMBER:{i=this.parent.getFields().createNumber(t);break}case this.parent.types.DATE:{i=this.parent.getFields().createDate(t);break}case this.parent.types.CUSTOM_DATE:{i=this.parent.getFields().createCustomDate(t);break}case this.parent.types.DEST_SELECTOR:{i=this.parent.getFields().createDestSelector(t);break}case this.parent.types.ENTITY_SELECTOR:{i=this.parent.getFields().createEntitySelector(t);break}case this.parent.types.CUSTOM:{i=this.parent.getFields().createCustom(t);break}case this.parent.types.CUSTOM_ENTITY:{i=this.parent.getFields().createCustomEntity(t);break}default:{break}}if(this.parent.getParam("ENABLE_ADDITIONAL_FILTERS")){var s=N.getInstance();var a=s.getAdditionalFilterButton({fieldId:t.NAME,enabled:t.ADDITIONAL_FILTER_ALLOWED});n.Dom.append(a,i);if(!t.ADDITIONAL_FILTER_ALLOWED){BX.Dom.addClass(i,"main-ui-filter-additional-filters-hide")}if(n.Type.isStringFilled(t.ADDITIONAL_FILTER)){s.initAdditionalFilter(i,t.ADDITIONAL_FILTER)}}if(BX.type.isDomNode(i)){i.dataset.name=t.NAME;i.FieldController=new BX.Filter.FieldController(i,this.parent);if(t.REQUIRED){var r=i.querySelector(".main-ui-filter-field-delete");if(r){BX.remove(r)}}}return i}},{key:"removeNotCompareVariables",value:function e(t,i){if(BX.type.isPlainObject(t)){var s=this.parent.dateTypes;var n=this.parent.additionalDateTypes;if("FIND"in t){delete t.FIND}if(!i){Object.keys(t).forEach((function(e){if(e.indexOf("_numsel")!==-1){delete t[e]}if(e.indexOf("_datesel")!==-1){var i=t[e];if(i===s.EXACT||i===s.RANGE||i===n.PREV_DAY||i===n.NEXT_DAY||i===n.MORE_THAN_DAYS_AGO||i===n.AFTER_DAYS||i===s.PREV_DAYS||i===s.NEXT_DAYS||i===s.YEAR||i===s.MONTH||i===s.QUARTER||i===s.NONE||i===s.CUSTOM_DATE){delete t[e]}}var a=this.parent.getFieldByName(e);if(t[e]===""&&(!a||!a.STRICT)){delete t[e]}}),this)}}}},{key:"isPresetValuesModified",value:function e(t){var i=this.getPreset(t);var s=this.parent.preparePresetSettingsFields(i.FIELDS);var n=this.parent.getFilterFieldsValues();this.removeNotCompareVariables(s);this.removeNotCompareVariables(n);var a=BX.Filter.Utils.sortObject(s);var r=BX.Filter.Utils.sortObject(n);return!Object.keys(a).every((function(e){return a[e]===r[e]||(BX.type.isPlainObject(a[e])||BX.type.isArray(a[e]))&&BX.Filter.Utils.objectsIsEquals(a[e],r[e])}))}},{key:"getAdditionalValues",value:function e(t){var i=this.getPreset(t);var s=i.FIELDS.filter((function(e){return!this.isEmptyField(e)}),this);var n=this.parent.preparePresetSettingsFields(s);var a=this.parent.getFilterFieldsValues();this.removeNotCompareVariables(n,true);this.removeNotCompareVariables(a,true);this.removeSameProperties(a,n);return a}},{key:"removeSameProperties",value:function e(t,i){if(BX.type.isPlainObject(t)&&BX.type.isPlainObject(i)){Object.keys(i).forEach((function(e){if(e in t){delete t[e]}}))}}},{key:"removeAdditionalField",value:function e(t){var i=this.getPreset(this.getCurrentPresetId());if(BX.type.isArray(i.ADDITIONAL)){i.ADDITIONAL=i.ADDITIONAL.filter((function(e){return e.NAME!==t}))}}},{key:"updatePresetFields",value:function e(t,i){var s=this;var n;var a;var r=[];if(BX.type.isPlainObject(t)&&"FIELDS"in t){n=t.FIELDS;if(BX.type.isArray(t.ADDITIONAL)){t.ADDITIONAL.filter((function(e){return s.parent.params.FIELDS.some((function(t){return e.NAME===t.NAME}))})).forEach((function(e){var t=false;e.IS_PRESET_FIELD=true;n.forEach((function(i,s){if(e.NAME===i.NAME){n[s]=e;t=true}}));if(!t){n.push(e)}}))}(n||[]).filter((function(e){return s.parent.params.FIELDS.some((function(t){return e.NAME===t.NAME}))})).forEach((function(e,t){e.TABINDEX=t+1;if(i){switch(e.TYPE){case this.parent.types.SELECT:{e.VALUE=e.ITEMS[0];break}case this.parent.types.MULTI_SELECT:{e.VALUE=[];break}case this.parent.types.DATE:{e.SUB_TYPE=e.SUB_TYPES[0];e.VALUES={_from:"",_to:"",_days:""};break}case this.parent.types.CUSTOM_DATE:{e.VALUE={days:[],months:[],years:[]};break}case this.parent.types.NUMBER:{e.SUB_TYPE=e.SUB_TYPES[0];e.VALUES={_from:"",_to:""};break}case this.parent.types.CUSTOM_ENTITY:{e.VALUES={_label:"",_value:""};break}case this.parent.types.CUSTOM:{e._VALUE="";break}default:{if("VALUE"in e){if(BX.type.isArray(e.VALUE)){e.VALUE=[]}else{e.VALUE=""}}break}}}r.push(this.createControl(e))}),this);this.parent.disableFieldsDragAndDrop();a=this.parent.getFieldListContainer();BX.cleanNode(a);if(r.length){r.forEach((function(e,i){if(BX.type.isDomNode(e)){if(t.ID!=="tmp_filter"&&t.ID!=="default_filter"&&!("IS_PRESET_FIELD"in n[i])&&!this.isEmptyField(n[i])){BX.addClass(e,this.parent.settings.classPresetField)}BX.append(e,a);if(BX.type.isString(n[i].HTML)){var s=BX.create("div");this.parent.getHiddenElement().appendChild(s);BX.html(s,n[i].HTML)}}}),this);this.parent.enableFieldsDragAndDrop()}}}},{key:"showCurrentPresetFields",value:function e(){var t=this.getCurrentPresetData();this.updatePresetFields(t)}},{key:"getCurrentPreset",value:function e(){return BX.Filter.Utils.getByClass(this.getContainer(),this.parent.settings.classPresetCurrent)}},{key:"getCurrentPresetId",value:function e(){var t=this.getCurrentPreset();var i=null;if(BX.type.isDomNode(t)){i=this.getPresetId(t)}else{i="tmp_filter"}return i}},{key:"getCurrentPresetData",value:function e(){var t=this.getCurrentPresetId();var i=null;if(BX.type.isNotEmptyString(t)){i=this.getPreset(t);i=this.extendPreset(i)}return i}},{key:"getContainer",value:function e(){return BX.Filter.Utils.getByClass(this.parent.getFilter(),this.parent.settings.classPresetsContainer)}},{key:"getPresets",value:function e(){return BX.Filter.Utils.getByClass(this.getContainer(),this.parent.settings.classPreset,true)}},{key:"getDefaultPresets",value:function e(){return BX.Filter.Utils.getByClass(this.getContainer(),this.parent.settings.classDefaultFilter,true)}},{key:"getPinnedPresetNode",value:function e(){return BX.Filter.Utils.getByClass(this.getContainer(),this.parent.settings.classPinnedPreset)}},{key:"isPinned",value:function e(t){return this.getPinnedPresetId()===t}},{key:"getPinnedPresetId",value:function e(){var t=this.getPinnedPresetNode();var i="default_filter";if(t){var s=BX.data(t,"id");i=s||i}return i}}]);return e}();e.Field=S;e.Api=_;e.Fields=w;e.Presets=x;e.AdditionalFilter=N})(this.BX.Filter=this.BX.Filter||{},BX.UI.EntitySelector,BX.Event,BX.Main,BX);
//# sourceMappingURL=script.map.js